Skip to content
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions R/QueryCondition.R
Original file line number Diff line number Diff line change
Expand Up @@ -107,13 +107,13 @@ tiledb_query_condition_combine <- function(lhs, rhs, op) {
parse_query_condition <- function(expr, debug=FALSE) {
.isComparisonOperator <- function(x) as.character(x) %in% c(">", ">=", "<", "<=", "==", "!=")
.isBooleanOperator <- function(x) as.character(x) %in% c("&&", "||", "!")
.isAscii <- function(x) grepl("^[a-zA-Z_]*$", x)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we want to keep the front anchor? Column names cannot start with digits...

Maybe "^[a-zA-Z_0-9]*" ?

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

But this is checking column values, right? So we don't want to miss something like "1a".

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gosh, you're right. I was so focussed on schema names.

In which case it is 'much worse' :) I.e. possibly payload is much more. Should we use [[:alpha:]] or a totally generic reg exp (meta) pattern.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure, I like [[:alpha:]]. It should improve detection for non-a-z characters too! I'll update.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Per ?regexp maybe [[:alnum:]] ?

.isInteger <- function(x) as.character(as.integer(x)) == x
.isDouble <- function(x) as.character(as.numeric(x)) == x && grepl("[\\.]", as.character(x))
.isAscii <- function(x) grepl("^[[:alnum:]_]+$", x)
.isInteger <- function(x) grepl("^[[:digit:]]+$", as.character(x))
.isDouble <- function(x) grepl("^[[:digit:]\\.]+$", as.character(x)) && length(grepRaw(".", as.character(x), fixed = TRUE, all = TRUE)) == 1
.getType <- function(x) {
if (.isAscii(as.character(x))) "ASCII"
else if (.isDouble(as.character(x))) "FLOAT64"
else "INT32"
if (isTRUE(.isInteger(x))) "INT32"
else if (isTRUE(.isDouble(x))) "FLOAT64"
else "ASCII"
}
.mapOpToCharacter <- function(x) switch(x,
`>` = "GT",
Expand Down
24 changes: 24 additions & 0 deletions inst/tinytest/test_querycondition.R
Original file line number Diff line number Diff line change
Expand Up @@ -194,3 +194,27 @@ arrwithqc <- tiledb_array(uri, as.data.frame=TRUE, query_condition=qc)
res <- arrwithqc[]
expect_equal(NROW(res), 165L)
expect_true(all(res$sex != "male"))

## check type inference for edge cases
edgecases <- data.frame(x1 = "a1", x2 = 1L, x3 = "_1", x4 = "1.1.1")

uri <- tempfile()
fromDataFrame(edgecases, uri, sparse=TRUE)

qcx1 <- tiledb::parse_query_condition(x1 == "a1")
arrx1 <- tiledb_array(uri, as.data.frame=TRUE, query_condition=qcx1)
res <- arrx1[]
expect_equal(res$x1, "a1")

qcx2 <- tiledb::parse_query_condition(x2 == 1L)
arrx2 <- tiledb_array(uri, as.data.frame=TRUE, query_condition=qcx2)
res <- arrx2[]
expect_equal(res$x2, 1L)

qcx3 <- tiledb::parse_query_condition(x3 == "_1")
arrx3 <- tiledb_array(uri, as.data.frame=TRUE, query_condition=qcx3)
expect_equal(arrx3[]$x3, "_1")

qcx4 <- tiledb::parse_query_condition(x4 == "1.1.1")
arrx4 <- tiledb_array(uri, as.data.frame=TRUE, query_condition=qcx4)
expect_equal(arrx4[]$x4, "1.1.1")