From 8f70ac03547dbb40c5be860b6110dcc62d57c240 Mon Sep 17 00:00:00 2001 From: Agisilaos Kounelis Date: Fri, 6 Mar 2026 10:10:26 +0200 Subject: [PATCH 1/2] Allow query conditions on dense array dimensions --- tiledb/query_condition.py | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/tiledb/query_condition.py b/tiledb/query_condition.py index ff68866e9a..0455b9fa3d 100644 --- a/tiledb/query_condition.py +++ b/tiledb/query_condition.py @@ -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 @@ -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.") From 62f61c59409bab4f3fc41d9a4958687287b1411f Mon Sep 17 00:00:00 2001 From: Agisilaos Kounelis Date: Fri, 6 Mar 2026 10:10:29 +0200 Subject: [PATCH 2/2] Add tests --- tiledb/tests/test_query_condition.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tiledb/tests/test_query_condition.py b/tiledb/tests/test_query_condition.py index 7caa7966ae..dca40825ed 100644 --- a/tiledb/tests/test_query_condition.py +++ b/tiledb/tests/test_query_condition.py @@ -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: