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
8 changes: 1 addition & 7 deletions tiledb/query_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
class QueryCondition:
"""
Class representing a TileDB query condition object for attribute and dimension
(sparse arrays only) filtering pushdown.
filtering pushdown.

A query condition is set with a string representing an expression
as defined by the grammar below. A more straight forward example of usage is
Expand Down Expand Up @@ -355,12 +355,6 @@ def get_variable_from_node(self, node: QueryConditionNodeElem) -> Any:
f"Incorrect type for variable name: {ast.dump(variable_node)}"
)

if self.array.schema.domain.has_dim(variable) and not self.array.schema.sparse:
raise TileDBError(
"Cannot apply query condition to dimensions on dense arrays. "
f"{variable} is a dimension."
)

if isinstance(node, ast.Call):
if node.func.id == "attr" and not self.array.schema.has_attr(variable):
raise TileDBError(f"{node.func.id} is not an attribute.")
Expand Down
25 changes: 20 additions & 5 deletions tiledb/tests/test_query_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -694,11 +694,26 @@ def test_deprecate_attr_cond(self):

def test_on_dense_dimensions(self):
with tiledb.open(self.create_input_array_UIDSA(sparse=False)) as A:
with pytest.raises(tiledb.TileDBError) as excinfo:
A.query(cond="2 <= d < 6")[:]
assert (
"Cannot apply query condition to dimensions on dense arrays"
) in str(excinfo.value)
result = A.query(cond="2 <= d < 6")[:]
expected = A[2:6]
assert_array_equal(result["U"][1:5], expected["U"])

# Cells outside the condition should be filled with fill values
assert result["U"][0] == np.iinfo(np.uint32).max

def test_on_dense_dimensions_combined_with_attrs(self):
with tiledb.open(self.create_input_array_UIDSA(sparse=False)) as A:
result = A.query(cond="2 <= d < 6 and U > 3")[:]
full = A[:]

# Build a mask matching the query condition "2 <= d < 6 and U > 3"
d = np.arange(1, 11, dtype=np.uint32)
match = (d >= 2) & (d < 6) & (full["U"] > 3)
fill = np.iinfo(np.uint32).max

# Matching cells keep their values, non-matching cells get fill
assert_array_equal(result["U"][match], full["U"][match])
assert_array_equal(result["U"][~match], fill)

def test_on_sparse_dimensions(self):
with tiledb.open(self.create_input_array_UIDSA(sparse=True)) as A:
Expand Down
Loading