Skip to content

Commit

Permalink
Do Not Require Attribute in Query Condition To Be Passed to Query (#1333
Browse files Browse the repository at this point in the history
)

* Do Not Require Attribute in Query Condition To Be Passed to Query

* Update HISTORY.md

* Review Feedback: Remove Commented Out Items

* Remove Outdated Query Condition Tests
  • Loading branch information
nguyenv authored Sep 28, 2022
1 parent 6d91699 commit 36e657e
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 13 deletions.
5 changes: 5 additions & 0 deletions HISTORY.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# In Progress

## API Changes
* Attributes in query conditions no longer need to be passed to `Array.query`'s `attr` arg [#1333](https://github.com/TileDB-Inc/TileDB-Py/pull/1333)

# TileDB-Py 0.17.4 Release Notes

## TileDB Embedded updates:
Expand Down
2 changes: 1 addition & 1 deletion tiledb/core.cc
Original file line number Diff line number Diff line change
Expand Up @@ -711,7 +711,7 @@ class PyQuery {
py::object init_pyqc = attr_cond.attr("init_query_condition");

try {
init_pyqc(pyschema_, attrs_);
attrs_ = init_pyqc(pyschema_, attrs_).cast<std::vector<std::string>>();
} catch (tiledb::TileDBError &e) {
TPY_ERROR_LOC(e.what());
} catch (py::error_already_set &e) {
Expand Down
7 changes: 3 additions & 4 deletions tiledb/query_condition.py
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,8 @@ def init_query_condition(self, schema: tiledb.ArraySchema, query_attrs: List[str
"be made up of one or more Boolean expressions."
)

return query_attrs


@dataclass
class QueryConditionTree(ast.NodeVisitor):
Expand Down Expand Up @@ -318,10 +320,7 @@ def get_att_from_node(self, node: QueryConditionNodeElem) -> Any:
raise tiledb.TileDBError(f"Attribute `{att}` not found in schema.")

if att not in self.query_attrs:
raise tiledb.TileDBError(
f"Attribute `{att}` given to filter in query's `attr_cond` "
"arg but not found in `attr` arg."
)
self.query_attrs.append(att)

return att

Expand Down
23 changes: 15 additions & 8 deletions tiledb/tests/test_query_condition.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import pytest

import numpy as np
from numpy.testing import assert_array_equal
import string

import tiledb
Expand Down Expand Up @@ -306,10 +307,6 @@ def test_check_attrs_sparse(self):
qc = tiledb.QueryCondition("U < 'one'")
A.query(attr_cond=qc, attrs=["U"])[:]

with self.assertRaises(tiledb.TileDBError):
qc = tiledb.QueryCondition("U < 1")
A.query(attr_cond=qc, attrs=["D"])[:]

def test_check_attrs_dense(self):
with tiledb.open(self.create_input_array_UIDSA(sparse=False)) as A:
mask = A.attr("U").fill
Expand All @@ -330,10 +327,6 @@ def test_check_attrs_dense(self):
qc = tiledb.QueryCondition("U < 'one'")
A.query(attr_cond=qc, attrs=["U"])[:]

with self.assertRaises(tiledb.TileDBError):
qc = tiledb.QueryCondition("U < 1")
A.query(attr_cond=qc, attrs=["D"])[:]

@pytest.mark.parametrize("sparse", [True, False])
def test_error_when_using_dim(self, sparse):
with tiledb.open(self.create_input_array_UIDSA(sparse)) as A:
Expand Down Expand Up @@ -665,3 +658,17 @@ def test_array_with_bool_but_unused(self):
qc = tiledb.QueryCondition("myint > 10")
result = A.query(attr_cond=qc, attrs=["myint"])[:]
assert all(result["myint"] > 10)

def test_do_not_return_queried_attr(self):
with tiledb.open(self.create_input_array_UIDSA(sparse=True)) as A:
qc = tiledb.QueryCondition("U < 3")

i_result = A.query(attr_cond=qc, attrs=["I", "U"])[:]
assert "I" in i_result.keys()
assert "U" in i_result.keys()
assert all(i_result["U"] < 5)

u_result = A.query(attr_cond=qc, attrs=["I"])[:]
assert "I" in u_result.keys()
assert "U" not in u_result.keys()
assert_array_equal(i_result["I"], u_result["I"])

0 comments on commit 36e657e

Please sign in to comment.