Skip to content

Commit

Permalink
Bugfix 1970: Give helpful error message if and/or/not operators are p…
Browse files Browse the repository at this point in the history
…rovided in QueryBuilder operations (#1976)

#### Reference Issues/PRs
Fixes #1970
  • Loading branch information
alexowens90 authored Nov 5, 2024
1 parent ab2b2df commit c2c6fce
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 5 deletions.
6 changes: 6 additions & 0 deletions python/arcticdb/version_store/processing.py
Original file line number Diff line number Diff line change
Expand Up @@ -202,6 +202,12 @@ def __rxor__(self, left):
else:
return self._rapply(left, _OperationType.XOR)

def __bool__(self):
raise UserInputException(
"'and', 'or', and 'not' operators not supported in ArcticDB querying operations,"
" please use the bitwise equivalents '&', '|', and '~' respectively"
)

def isin(self, *args):
value_list = value_list_from_args(*args)
return self._apply(value_list, _OperationType.ISIN)
Expand Down
12 changes: 12 additions & 0 deletions python/tests/unit/arcticdb/version_store/test_filtering.py
Original file line number Diff line number Diff line change
Expand Up @@ -1307,3 +1307,15 @@ def test_filter_with_column_slicing_defragmented(lmdb_version_store_tiny_segment
received = lib.read(symbol, query_builder=q).data
expected = df.query(pandas_query)
assert np.array_equal(expected, received) and (not expected.empty and not received.empty)


def test_filter_unsupported_boolean_operators():
with pytest.raises(UserInputException):
q = QueryBuilder()
q = q[q["a"] and q["b"]]
with pytest.raises(UserInputException):
q = QueryBuilder()
q = q[q["a"] or q["b"]]
with pytest.raises(UserInputException):
q = QueryBuilder()
q = q[not q["a"]]
11 changes: 6 additions & 5 deletions python/tests/unit/arcticdb/version_store/test_projection.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,15 +43,16 @@ def test_project_column_not_present(lmdb_version_store_v1):
def test_project_string_binary_arithmetic(lmdb_version_store_v1):
lib = lmdb_version_store_v1
symbol = "test_project_string_arithmetic"
lib.write(symbol, pd.DataFrame({"a": [0], "b": ["hello"], "c": ["bonjour"]}))
q = QueryBuilder()
operands = [q["a"], q["b"], q["c"], "0", 0]
lib.write(symbol, pd.DataFrame({"col_a": [0], "col_b": ["hello"], "col_c": ["bonjour"]}))
operands = ["col_a", "col_b", "col_c", "0", 0]
for lhs in operands:
for rhs in operands:
if (lhs == q["a"] and rhs in [q["a"], 0]) or (rhs == q["a"] and lhs in [q["a"], 0]):
if ((lhs == "col_a" and rhs in ["col_a", 0]) or
(rhs == "col_a" and lhs in ["col_a", 0]) or
(lhs in ["0", 0] and rhs in ["0", 0])):
continue
q = QueryBuilder()
q = q.apply("d", lhs + rhs)
q = q.apply("d", (q[lhs] if isinstance(lhs, str) and lhs.startswith("col_") else lhs) + (q[rhs] if isinstance(rhs, str) and rhs.startswith("col_") else rhs))
with pytest.raises(UserInputException):
lib.read(symbol, query_builder=q)

Expand Down

0 comments on commit c2c6fce

Please sign in to comment.