Skip to content

Commit

Permalink
Allow parse_query_condition() to work on dimensions
Browse files Browse the repository at this point in the history
Remove check that limits `parse_query_condition()` to attribute queries
when `ta` is provided

[SC-61458](https://app.shortcut.com/tiledb-inc/story/61458)
resolves #793
  • Loading branch information
mojaveazure committed Jan 7, 2025
1 parent 0d2ab61 commit bfb3ff8
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
8 changes: 0 additions & 8 deletions R/QueryCondition.R
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,6 @@ parse_query_condition <- function(expr, ta = NULL, debug = FALSE, strict = TRUE,
.errorFunction("No attribute '", attr, "' present.", call. = FALSE)
return(NULL)
}
if (ta@sil$status[ind] != 2) {
.errorFunction("Argument '", attr, "' is not an attribute.", call. = FALSE)
return(NULL)
}
ind
}
.getType <- function(x, tp, use_int64 = FALSE) {
Expand Down Expand Up @@ -259,10 +255,6 @@ parse_query_condition <- function(expr, ta = NULL, debug = FALSE, strict = TRUE,
.errorFunction("No attribute '", attr, "' present.", call. = FALSE)
return(NULL)
}
if (ta@sil$status[ind] != 2) {
.errorFunction("Argument '", attr, "' is not an attribute.", call. = FALSE)
return(NULL)
}
dtype <- ta@sil$types[ind]
is_enum <- ta@sil$enum[ind]
}
Expand Down
26 changes: 23 additions & 3 deletions inst/tinytest/test_querycondition.R
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@ if (Sys.getenv("CI") != "") set_allocation_size_preference(1024*1024*5)
ctx <- tiledb_ctx(limitTileDBCores())

## simple data.frame to test against
D <- data.frame(a=1:20,
b=seq(101,120)+0.5)
D <- data.frame(a = 1:20, b = seq(101, 120) + 0.5)
uri <- tempfile()
fromDataFrame(D, uri, sparse=TRUE)
arr <- tiledb_array(uri)
Expand Down Expand Up @@ -201,7 +200,28 @@ if (tiledb_version(TRUE) >= "2.17.0") {
expect_true(all(res$body_mass_g > 3500))
}

unlink(uri, recursive=TRUE)
unlink(uri, recursive = TRUE)

# Check that query conditions works on dimensions
uri <- tempfile()
fromDataFrame(infert, uri, col_index = "education", sparse = TRUE)
arr <- tiledb_array(uri)
qc <- parse_query_condition(education == "0-5yrs", ta = arr)
res <- tiledb_array(uri, query_condition = qc, return_as = "data.frame")[]
expect_equal(nrow(res), sum(infert$education == "0-5yrs"))
expect_identical(unique(res$education), "0-5yrs")

if (tiledb_version(TRUE) >= "2.17.0") {
qc2 <- parse_query_condition(
education %in% c("0-5yrs", "12+ yrs"),
ta = arr
)
res <- tiledb_array(uri, query_condition = qc2, return_as = "data.frame")[]
expect_equal(nrow(res), sum(infert$education %in% c("0-5yrs", "12+ yrs")))
expect_true(all(res$education %in% c("0-5yrs", "12+ yrs")))
}

unlink(uri, recursive = TRUE)

## (some) r-universe builds are/were breaking here
if (Sys.getenv("MY_UNIVERSE", "") != "") exit_file("Skip remainder at r-universe")
Expand Down

0 comments on commit bfb3ff8

Please sign in to comment.