Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do Not Require Attribute in Query Condition To Be Passed to Query #1333

Merged
Show file tree
Hide file tree
Changes from 2 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
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
11 changes: 7 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,11 @@ 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)
# raise tiledb.TileDBError(
nguyenv marked this conversation as resolved.
Show resolved Hide resolved
# f"Attribute `{att}` given to filter in query's `attr_cond` "
# "arg but not found in `attr` arg."
# )

return att

Expand Down
15 changes: 15 additions & 0 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 @@ -665,3 +666,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"])