Skip to content

Commit 0adadc1

Browse files
authored
Error out if query condition given empty set (#1877)
1 parent 82718a8 commit 0adadc1

File tree

2 files changed

+16
-0
lines changed

2 files changed

+16
-0
lines changed

tiledb/query_condition.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,10 @@ def visit_Compare(self, node: Type[ast.Compare]) -> qc.PyQueryCondition:
222222

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

226230
if self.array.schema.has_attr(variable):
227231
enum_label = self.array.attr(variable).enum_label

tiledb/tests/test_query_condition.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -551,6 +551,12 @@ def test_in_operator_sparse(self):
551551
for val in result["U"]:
552552
assert val not in [5, 6, 7]
553553

554+
with pytest.raises(tiledb.TileDBError) as exc_info:
555+
A.query(cond="U not in []")[:]
556+
assert "At least one value must be provided to the set membership" in str(
557+
exc_info.value
558+
)
559+
554560
def test_in_operator_dense(self):
555561
with tiledb.open(self.create_input_array_UIDSA(sparse=False)) as A:
556562
U_mask = A.attr("U").fill
@@ -582,6 +588,12 @@ def test_in_operator_dense(self):
582588
for val in self.filter_dense(result["U"], U_mask):
583589
assert val not in [5, 6, 7]
584590

591+
with pytest.raises(tiledb.TileDBError) as exc_info:
592+
A.query(cond="U not in []")[:]
593+
assert "At least one value must be provided to the set membership" in str(
594+
exc_info.value
595+
)
596+
585597
@pytest.mark.skipif(not has_pandas(), reason="pandas not installed")
586598
def test_dense_datetime(self):
587599
import pandas as pd

0 commit comments

Comments
 (0)