Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Apply styler::style_pkg() #778

Merged
merged 7 commits into from
Oct 29, 2024
Merged
Show file tree
Hide file tree
Changes from 6 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.30.2.1
Version: 0.30.2.2
Title: Modern Database Engine for Complex Data Based on Multi-Dimensional Arrays
Authors@R: c(
person("TileDB, Inc.", role = c("aut", "cph")),
Expand Down
1 change: 1 addition & 0 deletions NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Run `clang-format` on non-autogen C++ source code
* Update unit tests to expect dense current domain
* Support parentheses in query conditions
* memory alloc: Accomodate zero buffer size estimate v2

# tiledb 0.30.2

Expand Down
199 changes: 120 additions & 79 deletions R/Array.R
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,9 @@
#' in case the array should be encryption.
#'
#' @examples
#' \dontshow{ctx <- tiledb_ctx(limitTileDBCores())}
#' \dontshow{
#' ctx <- tiledb_ctx(limitTileDBCores())
#' }
#' \dontrun{
#' pth <- tempdir()
#' dom <- tiledb_domain(dims = c(tiledb_dim("d1", c(1L, 10L), type = "INT32")))
Expand All @@ -38,26 +40,28 @@
#' }
#'
#' @export
tiledb_array_create <- function(uri, schema, encryption_key) { #, ctx = tiledb_get_context()) {
stopifnot("The 'uri' argument must be a string scalar" = !missing(uri) && is.scalar(uri, "character"),
"The 'schema' argument must be a tiledb_array_schema object" = !missing(schema) && is(schema, "tiledb_array_schema"))
if (!missing(encryption_key)) {
## old interface
needreset <- FALSE
config <- oldconfig <- tiledb_config()
if (config["sm.encryption_type"] != "AES_256_GCM" ||
config["sm.encryption_key"] != encryption_key) {
config["sm.encryption_type"] <- "AES_256_GCM"
config["sm.encryption_key"] <- encryption_key
ctx <- tiledb::tiledb_ctx(config)
needreset <- TRUE
}
uri <- libtiledb_array_create(uri, schema@ptr)
if (needreset) ctx <- tiledb::tiledb_ctx(oldconfig)
invisible(uri)
} else {
invisible(libtiledb_array_create(uri, schema@ptr))
tiledb_array_create <- function(uri, schema, encryption_key) { # , ctx = tiledb_get_context()) {
stopifnot(
"The 'uri' argument must be a string scalar" = !missing(uri) && is.scalar(uri, "character"),
"The 'schema' argument must be a tiledb_array_schema object" = !missing(schema) && is(schema, "tiledb_array_schema")
)
if (!missing(encryption_key)) {
## old interface
needreset <- FALSE
config <- oldconfig <- tiledb_config()
if (config["sm.encryption_type"] != "AES_256_GCM" ||
config["sm.encryption_key"] != encryption_key) {
config["sm.encryption_type"] <- "AES_256_GCM"
config["sm.encryption_key"] <- encryption_key
ctx <- tiledb::tiledb_ctx(config)
needreset <- TRUE
}
uri <- libtiledb_array_create(uri, schema@ptr)
if (needreset) ctx <- tiledb::tiledb_ctx(oldconfig)
invisible(uri)
} else {
invisible(libtiledb_array_create(uri, schema@ptr))
}
}

##' Open a TileDB Array
Expand All @@ -68,11 +72,14 @@ tiledb_array_create <- function(uri, schema, encryption_key) { #, ctx = tiledb_g
##' @return The TileDB Array object but opened for reading or writing
##' @importFrom methods .hasSlot
##' @export
tiledb_array_open <- function(arr,
type = if (tiledb_version(TRUE) >= "2.12.0")
c("READ", "WRITE", "DELETE", "MODIFY_EXCLUSIVE")
else
c("READ", "WRITE")) {
tiledb_array_open <- function(
arr,
type = if (tiledb_version(TRUE) >= "2.12.0") {
c("READ", "WRITE", "DELETE", "MODIFY_EXCLUSIVE")
} else {
c("READ", "WRITE")
}
) {
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr))
type <- match.arg(type)

Expand All @@ -92,9 +99,11 @@ tiledb_array_open <- function(arr,
##' @param timestamp A Datetime object that will be converted to millisecond granularity
##' @return The TileDB Array object but opened for reading or writing
##' @export
tiledb_array_open_at <- function(arr, type=c("READ","WRITE"), timestamp) {
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr),
"The 'timestamp' argument must be a time object" = inherits(timestamp, "POSIXct"))
tiledb_array_open_at <- function(arr, type = c("READ", "WRITE"), timestamp) {
stopifnot(
"The 'arr' argument must be a tiledb_array object" = .isArray(arr),
"The 'timestamp' argument must be a time object" = inherits(timestamp, "POSIXct")
)
type <- match.arg(type)
ctx <- tiledb_get_context()
if (.hasSlot(arr, "encryption_key") && length(arr@encryption_key) > 0) {
Expand Down Expand Up @@ -123,8 +132,8 @@ tiledb_array_close <- function(arr) {
##' @return A boolean indicating whether the TileDB Array object is open
##' @export
tiledb_array_is_open <- function(arr) {
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr))
libtiledb_array_is_open(arr@ptr)
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr))
libtiledb_array_is_open(arr@ptr)
}

##' Check for Homogeneous Domain
Expand All @@ -137,8 +146,10 @@ tiledb_array_is_homogeneous <- function(arr) {
## there is a non-exported call at the C level we could use instead
sch <- schema(arr)
dom <- domain(sch)
domaintype <- sapply(libtiledb_domain_get_dimensions(dom@ptr),
libtiledb_dim_get_datatype)
domaintype <- sapply(
libtiledb_domain_get_dimensions(dom@ptr),
libtiledb_dim_get_datatype
)
n <- length(unique(domaintype))
n == 1
}
Expand All @@ -153,8 +164,10 @@ tiledb_array_is_heterogeneous <- function(arr) {
## there is a non-exported call at the C level we could use instead
sch <- schema(arr)
dom <- domain(sch)
domaintype <- sapply(libtiledb_domain_get_dimensions(dom@ptr),
libtiledb_dim_get_datatype)
domaintype <- sapply(
libtiledb_domain_get_dimensions(dom@ptr),
libtiledb_dim_get_datatype
)
n <- length(unique(domaintype))
n > 1
}
Expand All @@ -167,30 +180,44 @@ tiledb_array_is_heterogeneous <- function(arr) {
##' @param ctx A tiledb_ctx object (optional)
##' @return A boolean indicating success
##' @export
tiledb_array_delete_fragments <- function(arr, ts_start, ts_end, ctx = tiledb_get_context()) {
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr),
"The 'ts_start' argument must be a time object" = inherits(ts_start, "POSIXct"),
"The 'ts_end' argument must be a time object" = inherits(ts_end, "POSIXct"))
libtiledb_array_delete_fragments(ctx@ptr, arr@ptr, ts_start, ts_end)
invisible(TRUE)
tiledb_array_delete_fragments <- function(
arr,
ts_start,
ts_end,
ctx = tiledb_get_context()
) {
stopifnot(
"The 'arr' argument must be a tiledb_array object" = .isArray(arr),
"The 'ts_start' argument must be a time object" = inherits(ts_start, "POSIXct"),
"The 'ts_end' argument must be a time object" = inherits(ts_end, "POSIXct")
)
libtiledb_array_delete_fragments(ctx@ptr, arr@ptr, ts_start, ts_end)
invisible(TRUE)
}

##' Delete fragments written given by their URIs
##'
##' @param arr A TileDB Array object as for example returned by \code{tiledb_array()}
##' @param arr A TileDB Array object as for example returned by
##' \code{tiledb_array()}
##' @param fragments A character vector with fragment URIs
##' @param ctx A tiledb_ctx object (optional)
##' @return A boolean indicating success
##' @export
tiledb_array_delete_fragments_list <- function(arr, fragments, ctx = tiledb_get_context()) {
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr),
"The 'fragments' argument must be a character vector" = is.character(fragments))
if (tiledb_version(TRUE) >= "2.18.0") {
libtiledb_array_delete_fragments_list(ctx@ptr, arr@ptr, fragments)
} else {
message("This function is only available with TileDB 2.18.0 or later")
}
invisible(TRUE)
tiledb_array_delete_fragments_list <- function(
arr,
fragments,
ctx = tiledb_get_context()
) {
stopifnot(
"The 'arr' argument must be a tiledb_array object" = .isArray(arr),
"The 'fragments' argument must be a character vector" = is.character(fragments)
)
if (tiledb_version(TRUE) >= "2.18.0") {
libtiledb_array_delete_fragments_list(ctx@ptr, arr@ptr, fragments)
} else {
message("This function is only available with TileDB 2.18.0 or later")
}
invisible(TRUE)
}

##' Check for Enumeration (aka Factor aka Dictionary)
Expand All @@ -199,13 +226,13 @@ tiledb_array_delete_fragments_list <- function(arr, fragments, ctx = tiledb_get_
##' @return A boolean indicating if the array has homogeneous domains
##' @export
tiledb_array_has_enumeration <- function(arr) {
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr))
ctx <- tiledb_get_context()
if (!tiledb_array_is_open(arr)) {
arr <- tiledb_array_open(arr, "READ")
on.exit(tiledb_array_close(arr))
}
return(libtiledb_array_has_enumeration_vector(ctx@ptr, arr@ptr))
stopifnot("The 'arr' argument must be a tiledb_array object" = .isArray(arr))
ctx <- tiledb_get_context()
if (!tiledb_array_is_open(arr)) {
arr <- tiledb_array_open(arr, "READ")
on.exit(tiledb_array_close(arr))
}
return(libtiledb_array_has_enumeration_vector(ctx@ptr, arr@ptr))
}

##' Run an aggregate query on the given (sparse) array and attribute
Expand All @@ -219,27 +246,33 @@ tiledb_array_has_enumeration <- function(arr) {
##' @param nullable A boolean toggle whether the attribute is nullable
##' @return The value of the aggregation
##' @export
tiledb_array_apply_aggregate <- function(array, attrname,
operation = c("Count", "NullCount", "Min", "Max",
"Mean", "Sum"),
nullable = TRUE) {
stopifnot("The 'array' argument must be a TileDB Array object" = is(array, "tiledb_array"),
"The 'array' must be a sparse TileDB Array" = is.sparse(schema(array)),
"The 'attrname' argument must be character" = is.character(attrname),
"The 'operation' argument must be character" = is.character(operation),
"The 'nullable' argument must be logical" = is.logical(nullable))
tiledb_array_apply_aggregate <- function(
array,
attrname,
operation = c("Count", "NullCount", "Min", "Max", "Mean", "Sum"),
nullable = TRUE
) {
stopifnot(
"The 'array' argument must be a TileDB Array object" = is(array, "tiledb_array"),
"The 'array' must be a sparse TileDB Array" = is.sparse(schema(array)),
"The 'attrname' argument must be character" = is.character(attrname),
"The 'operation' argument must be character" = is.character(operation),
"The 'nullable' argument must be logical" = is.logical(nullable)
)

operation <- match.arg(operation)
operation <- match.arg(operation)

if (tiledb_array_is_open(array))
array <- tiledb_array_close(array)
if (tiledb_array_is_open(array)) {
array <- tiledb_array_close(array)
}

query <- tiledb_query(array, "READ")
query <- tiledb_query(array, "READ")

if (! tiledb_query_get_layout(query) %in% c("UNORDERED", "GLOBAL_ORDER"))
query <- tiledb_query_set_layout(query, "UNORDERED")
if (!tiledb_query_get_layout(query) %in% c("UNORDERED", "GLOBAL_ORDER")) {
query <- tiledb_query_set_layout(query, "UNORDERED")
}

libtiledb_query_apply_aggregate(query@ptr, attrname, operation, nullable)
libtiledb_query_apply_aggregate(query@ptr, attrname, operation, nullable)
}

##' Upgrade an Array to the current TileDB Array Schema Format
Expand All @@ -249,10 +282,18 @@ tiledb_array_apply_aggregate <- function(array, attrname,
##' @param ctx A tiledb_ctx object (optional)
##' @return Nothing is returned as the function is invoked for its side effect
##' @export
tiledb_array_upgrade_version <- function(array, config = NULL, ctx = tiledb_get_context()) {
stopifnot("The 'array' argument must be a TileDB Array object" = is(array, "tiledb_array"),
"The 'config' argument must be NULL or a TileDB Config" =
is.null(config) || is(config, "tiledb_config"))
libtiledb_array_upgrade_version(ctx@ptr, array@ptr, array@uri,
if (is.null(config)) NULL else config@ptr)
tiledb_array_upgrade_version <- function(
array,
config = NULL,
ctx = tiledb_get_context()
) {
stopifnot(
"The 'array' argument must be a TileDB Array object" = is(array, "tiledb_array"),
"The 'config' argument must be NULL or a TileDB Config" =
is.null(config) || is(config, "tiledb_config")
)
libtiledb_array_upgrade_version(
ctx@ptr, array@ptr, array@uri,
if (is.null(config)) NULL else config@ptr
)
}
Loading
Loading