Skip to content

Commit

Permalink
Add tiledb_array_is_open_for_reading()/writing() (#808)
Browse files Browse the repository at this point in the history
* Add `tiledb_array_is_open_for_reading()/writing()`

* unit-test coverage

* DESCRIPTION/NEW.md

* NAMESPACE

* Rscript -e "devtools::document()"

* typofix

* code-review feedback

* Apply suggestions from code review

Co-authored-by: Paul Hoffman <[email protected]>

* fix a fail

---------

Co-authored-by: Paul Hoffman <[email protected]>
  • Loading branch information
johnkerl and mojaveazure authored Feb 18, 2025
1 parent aeb0388 commit 08ff53f
Show file tree
Hide file tree
Showing 7 changed files with 71 additions and 1 deletion.
2 changes: 1 addition & 1 deletion DESCRIPTION
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
Package: tiledb
Type: Package
Version: 0.31.0.3
Version: 0.31.0.4
Title: Modern Database Engine for Complex Data Based on Multi-Dimensional Arrays
Authors@R: c(
person("TileDB, Inc.", role = c("aut", "cph")),
Expand Down
2 changes: 2 additions & 0 deletions NAMESPACE
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,8 @@ export(tiledb_array_has_enumeration)
export(tiledb_array_is_heterogeneous)
export(tiledb_array_is_homogeneous)
export(tiledb_array_is_open)
export(tiledb_array_is_open_for_reading)
export(tiledb_array_is_open_for_writing)
export(tiledb_array_open)
export(tiledb_array_open_at)
export(tiledb_array_schema)
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
* Allow `parse_query_condition()` to work on dimensions when an array is passed
* Add `tiledb_vfs_copy_dir()`, a wrapper for the `vfs_copy_dir()` function
* Print values for `tiledb_schema_get_types()` and `tiledb_schema_get_names()` [#805](https://github.com/TileDB-Inc/TileDB-R/issues/805)
* Add `tiledb_array_is_open_for_reading()/writing()` [#806](https://github.com/TileDB-Inc/TileDB-R/issues/806)

# tiledb 0.31.0

Expand Down
22 changes: 22 additions & 0 deletions R/Array.R
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,28 @@ tiledb_array_is_open <- function(arr) {
libtiledb_array_is_open(arr@ptr)
}

##' Test if TileDB Array is open for reading
##'
##' @param arr A TileDB Array object as for example returned by `tiledb_array()`
##' @return A boolean indicating whether the TileDB Array object is open, and
##' the mode is "READ".
##' @export
tiledb_array_is_open_for_reading <- function(arr) {
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr))
return(libtiledb_array_is_open_for_reading(arr@ptr))
}

##' Test if TileDB Array is open for writing
##'
##' @param arr A TileDB Array object as for example returned by `tiledb_array()`
##' @return A boolean indicating whether the TileDB Array object is open, and
##' the mode is "WRITE".
##' @export
tiledb_array_is_open_for_writing <- function(arr) {
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr))
return(libtiledb_array_is_open_for_writing(arr@ptr))
}

##' Check for Homogeneous Domain
##'
##' @param arr A TileDB Array object
Expand Down
9 changes: 9 additions & 0 deletions inst/tinytest/test_tiledbarray.R
Original file line number Diff line number Diff line change
Expand Up @@ -976,8 +976,12 @@ data <- c(1L, 2L, 3L)
arr <- tiledb_array(uri = tmp)
arr[I, J] <- data
expect_false(tiledb_array_is_open(arr))
expect_false(tiledb_array_is_open_for_reading(arr))
expect_false(tiledb_array_is_open_for_writing(arr))
arr <- tiledb_array_open(arr)
expect_true(tiledb_array_is_open(arr))
expect_true(tiledb_array_is_open_for_reading(arr))
expect_false(tiledb_array_is_open_for_writing(arr))
expect_equal(tiledb_array_get_non_empty_domain_from_index(arr, 1), c(1, 3))
expect_equal(tiledb_array_get_non_empty_domain_from_name(arr, "d1"), c(1, 3))
expect_equal(tiledb_array_get_non_empty_domain_from_index(arr, 2), c("a", "c"))
Expand Down Expand Up @@ -1124,6 +1128,9 @@ schema <- tiledb_array_schema(tiledb_domain(dims=c(tiledb_dim("d1", c(1L, N), ti
attrs=tiledb_attr("x", type="FLOAT64"))
tiledb_array_create(uri, schema)
obj <- tiledb_array(uri, attrs="x", query_type="WRITE")
# No tiledb_array_open yet, so, both false
expect_false(tiledb_array_is_open_for_reading(obj))
expect_false(tiledb_array_is_open_for_writing(obj))
M <- matrix(runif(N*K), N, K)
obj[] <- M # prior to #246 this write had a write data type
chk <- tiledb_array(uri, return_as="matrix")
Expand Down Expand Up @@ -1578,6 +1585,8 @@ expect_false(tiledb_array_is_open(arr))
arr <- tiledb_array(uri, keep_open=TRUE)
res <- arr[]
expect_true(tiledb_array_is_open(arr))
expect_true(tiledb_array_is_open_for_reading(arr))
expect_false(tiledb_array_is_open_for_writing(arr))
arr <- tiledb_array_close(arr)
expect_false(tiledb_array_is_open(arr))

Expand Down
18 changes: 18 additions & 0 deletions man/tiledb_array_is_open_for_reading.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

18 changes: 18 additions & 0 deletions man/tiledb_array_is_open_for_writing.Rd

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 08ff53f

Please sign in to comment.