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

Minor interface completion at R level allowing nullable and varnum for vec #538

Merged
merged 3 commits into from
Apr 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 3 additions & 1 deletion NEWS.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

* Group objects can be opened while supplying a Config object when 2.15.1 or newer is used (#535, #536)

* For character column buffer allocations, the helper function now accepts a `nullable` option (#537)
* For character column buffer allocations, the R function now accepts a `nullable` option (#537)

* For standard buffer allocations, the R function now accepts `nullable` and `varnum` options (#538)

## Build and Test Systems

Expand Down
16 changes: 11 additions & 5 deletions R/Query.R
Original file line number Diff line number Diff line change
Expand Up @@ -199,13 +199,19 @@ tiledb_query_set_buffer_ptr_char <- function(query, attr, bufptr) {
#' @param query A TileDB Query object
#' @param datatype A character value containing the data type
#' @param ncells A number of elements (not bytes)
#' @param nullable Optional boolean parameter indicating whether missing values
#' are allowed (for which another column is allocated), default is FALSE
#' @param varnum Option intgeter parameter for the number of elemements per variable,
#' default is one
#' @return An external pointer to the allocated buffer object
#' @export
tiledb_query_buffer_alloc_ptr <- function(query, datatype, ncells) {
stopifnot(`Argument 'query' must be a tiledb_query object` = is(query, "tiledb_query"),
`Argument 'datatype' must be a character object` = is.character(datatype),
`Argument 'ncells' must be numeric` = is.numeric(ncells))
bufptr <- libtiledb_query_buffer_alloc_ptr(datatype, ncells)
tiledb_query_buffer_alloc_ptr <- function(query, datatype, ncells, nullable=FALSE, varnum=1) {
stopifnot("Argument 'query' must be a tiledb_query object" = is(query, "tiledb_query"),
"Argument 'datatype' must be a character object" = is.character(datatype),
"Argument 'ncells' must be numeric" = is.numeric(ncells),
"Argument 'nullable' must be logical" = is.logical(nullable),
"Argument 'varnum' must be integer or numeric" = is.integer(varnum) || is.numeric(varnum))
bufptr <- libtiledb_query_buffer_alloc_ptr(datatype, ncells, nullable, varnum)
bufptr
}

Expand Down
24 changes: 24 additions & 0 deletions inst/tinytest/test_query.R
Original file line number Diff line number Diff line change
Expand Up @@ -273,3 +273,27 @@ tiledb_query_finalize(qry)
oo <- tiledb_array(uri, return_as="data.frame", strings_as_factors=TRUE)[]

expect_equal(nrow(oo), 84) # instead of 344 pre-deletion


## for #537 #538: allocate char buffer and normal buffer with nullable
## quick data frame with NAs
sdf <- data.frame(rows=1:5,
keys=c("ABC", NA, "GHI", "JKL", "MNO"),
vals=c(NA,sqrt(2:3),NA,sqrt(5)))
uri <- tempfile()
fromDataFrame(sdf, uri, col_index=1)

arr <- tiledb_array(uri)
qry <- tiledb_query(arr, "READ")
N <- 10
rows <- integer(N)
keysbuf <- tiledb_query_alloc_buffer_ptr_char(N, N*8, TRUE)
valsbuf <- tiledb_query_buffer_alloc_ptr(qry, "FLOAT64", N, TRUE)

expect_silent(tiledb_query_set_buffer(qry, "rows", rows))
expect_silent(tiledb_query_set_buffer_ptr_char(qry, "keys", keysbuf))
expect_silent(tiledb_query_set_buffer_ptr(qry, "vals", valsbuf))
expect_silent(tiledb_query_set_subarray(qry, c(1L,5L), "INT32"))
expect_silent(tiledb_query_submit(qry))
expect_silent(tiledb_query_finalize(qry))
expect_equal(tiledb_query_status(qry), "COMPLETE")
14 changes: 13 additions & 1 deletion man/tiledb_query_buffer_alloc_ptr.Rd

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