Skip to content

Commit

Permalink
Error out if query condition given empty set
Browse files Browse the repository at this point in the history
  • Loading branch information
nguyenv committed Dec 4, 2023
1 parent 22ff29a commit e4edcf0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 0 deletions.
3 changes: 3 additions & 0 deletions tiledb/query_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,9 @@ def visit_Compare(self, node: Type[ast.Compare]) -> qc.PyQueryCondition:

variable = node.left.id
values = [self.get_value_from_node(val) for val in self.visit(rhs)]
if len(values) == 0:
raise TileDBError("At least one value must be provided to "
"the set membership")

if self.array.schema.has_attr(variable):
enum_label = self.array.attr(variable).enum_label
Expand Down
8 changes: 8 additions & 0 deletions tiledb/tests/test_query_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -550,6 +550,10 @@ def test_in_operator_sparse(self):
result = A.query(cond="U not in [5, 6, 7]")[:]
for val in result["U"]:
assert val not in [5, 6, 7]

with pytest.raises(tiledb.TileDBError) as exc_info:
A.query(cond="U not in []")[:]
assert "At least one value must be provided to the set membership" in str(exc_info.value)

def test_in_operator_dense(self):
with tiledb.open(self.create_input_array_UIDSA(sparse=False)) as A:
Expand Down Expand Up @@ -581,6 +585,10 @@ def test_in_operator_dense(self):
result = A.query(cond="U not in [5, 6, 7]")[:]
for val in self.filter_dense(result["U"], U_mask):
assert val not in [5, 6, 7]

with pytest.raises(tiledb.TileDBError) as exc_info:
A.query(cond="U not in []")[:]
assert "At least one value must be provided to the set membership" in str(exc_info.value)

@pytest.mark.skipif(not has_pandas(), reason="pandas not installed")
def test_dense_datetime(self):
Expand Down

0 comments on commit e4edcf0

Please sign in to comment.