-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
TileDBArray$reopen()
public
Expose `TileDBArray$reopen()` as a public API; as R does not have context managers, there's no native way to do the Python construct ```python cls = type(arr) with cls.open(arr.uri, "r") as readarr: # do a read operation even though the array is open in write ``` This PR exposes `$reopen()` to reopen an array in a new mode Modified SOMA methods: - `TileDBArray$reopen()`: now public and includes new default for reopening: if `arr$mode()` is `READ`, will automatically reopen in `WRITE` and vice versa - `TileDBObject$is_open()`: now uses `TileDBObject$mode()` to determine if the array is open as `TileDBObject$mode()` already processes `TileDBObject$private$.mode`
- Loading branch information
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,99 @@ | ||
test_that("Test reopen works on arrays", { | ||
shape <- c(500L, 100L) | ||
for (cls in c("SOMADataFrame", "SOMASparseNDArray", "SOMADenseNDArray")) { | ||
uri <- withr::local_tempdir(paste("soma", cls, "array", "reopen", sep = "-")) | ||
arr <- switch( | ||
EXPR = cls, | ||
SOMADataFrame = SOMADataFrameCreate( | ||
uri, | ||
schema = arrow::infer_schema(data.frame( | ||
soma_joinid = bit64::integer64(), | ||
int = integer() | ||
)) | ||
), | ||
SOMASparseNDArray = SOMASparseNDArrayCreate( | ||
uri, | ||
type = arrow::int32(), | ||
shape = shape | ||
), | ||
SOMADenseNDArray = SOMADenseNDArrayCreate( | ||
uri, | ||
type = arrow::int32(), | ||
shape = shape | ||
) | ||
) | ||
expect_s3_class(arr, cls) | ||
expect_identical( | ||
arr$mode(), | ||
"WRITE", | ||
info = sprintf("%sCreate() returns object open for 'WRITE'", cls) | ||
) | ||
expect_true( | ||
arr$is_open(), | ||
info = sprintf("%s is open when mode is 'WRITE'", cls) | ||
) | ||
|
||
lab <- sprintf("%s$reopen()", cls) | ||
is_open <- sprintf("%s$reopen() returns an object object", cls) | ||
|
||
# Test implicit WRITE -> READ | ||
expect_invisible(arr$reopen(), label = lab) | ||
expect_identical( | ||
arr$mode(), | ||
"READ", | ||
info = sprintf("%s$reopen() when mode is 'WRITE' reopens as 'READ'", cls) | ||
) | ||
expect_true(arr$is_open(), info = is_open) | ||
|
||
# Test implicit READ -> WRITE | ||
expect_invisible(arr$reopen(), label = lab) | ||
expect_identical( | ||
arr$mode(), | ||
"WRITE", | ||
info = sprintf("%s$reopen() when mode is 'READ' reopens as 'WRITE'", cls) | ||
) | ||
expect_true(arr$is_open(), info = is_open) | ||
|
||
# Test reopening in the same mode | ||
orig <- arr$mode() | ||
expect_invisible(arr$reopen(orig), label = lab) | ||
expect_identical( | ||
arr$mode(), | ||
orig, | ||
info = sprintf("%s$reopen() with an identical mode returns the same mode", cls) | ||
) | ||
expect_true(arr$is_open(), info = is_open) | ||
|
||
# Test reopen from close | ||
expect_no_condition(arr$close()) | ||
expect_identical(arr$mode(), "CLOSED") | ||
expect_false(arr$is_open()) | ||
|
||
for (mode in c("READ", "WRITE")) { | ||
expect_invisible( | ||
arr$reopen(mode), | ||
label = sprintf("%s$reopen('%s') from closed", cls, mode) | ||
) | ||
expect_identical( | ||
arr$mode(), | ||
mode, | ||
info = sprintf("%s$reopen('%s') returns a mode of '%s'", cls, mode, mode) | ||
) | ||
expect_true( | ||
arr$is_open(), | ||
info = sprintf("%s$reopen('%s') from CLOSED returns an open object", cls, mode) | ||
) | ||
expect_no_condition(arr$close()) | ||
} | ||
|
||
arr$close() | ||
expect_error(arr$reopen()) | ||
|
||
# Test assertions | ||
expect_error(arr$reopen("tomato")) | ||
expect_error(arr$reopen(TRUE)) | ||
expect_error(arr$reopen(1L)) | ||
|
||
arr$close() | ||
} | ||
}) |