Skip to content
Merged
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
16 changes: 16 additions & 0 deletions inst/tinytest/test_querycondition.R
Original file line number Diff line number Diff line change
Expand Up @@ -284,3 +284,19 @@ qc <- parse_query_condition(year < 2008 || year > 2010)
arr <- tiledb_array(uri, as.data.frame=TRUE, query_condition=qc)
expect_equal(NROW(arr[]),
sum(with(penguins, year < 2008 | year > 2010)))

## Overlapping ranges
qc <- parse_query_condition(year < 2009 && year < 2010)
arr <- tiledb_array(uri, as.data.frame=TRUE, query_condition=qc)
expect_equal(NROW(arr[]),
sum(with(penguins, year < 2009)))

qc <- parse_query_condition(year <= 2009 && year >= 2009)
arr <- tiledb_array(uri, as.data.frame=TRUE, query_condition=qc)
expect_equal(NROW(arr[]),
sum(with(penguins, year == 2009)))

qc <- parse_query_condition(year < 2009 || year < 2010)
Copy link
Copy Markdown
Member

@aaronwolen aaronwolen Jun 15, 2022

Choose a reason for hiding this comment

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

Shouldn't this be | rather than || for element-wise comparisons? Ditto for && above.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Whooops. Excellent catch. Will fix.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Sorry, actually no: that is a 'token' for parse_query_condidtion() and not an R element-by-element operator.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Oh I see now:

TileDB-R/R/QueryCondition.R

Lines 132 to 135 in 8f1d2fa

.mapBoolToCharacter <- function(x) switch(x,
`&&` = "AND",
`||` = "OR",
`!` = "NOT")
.

Maybe we should translate |/& to ||/&& behind the scenes for R folks?

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Actually, any reason not to use the short-form of these as the tokens for AND/OR? (Sorry, I know we've wandered away from the point of this PR).

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Funny you went to the source, I did too :)

My feeling was we should definitely also support AND and OR (and, though currently a no-op) NOT. I feel less strongly about & and | but I suppose we could. In many other programming languages the double && or || is common which is why I went with it.

Maybe this discussion should be another issue or SC ticket. Lemme me merge this now first.

arr <- tiledb_array(uri, as.data.frame=TRUE, query_condition=qc)
expect_equal(NROW(arr[]),
sum(with(penguins, year < 2010)))