Skip to content

Commit

Permalink
Merge pull request #568 from DagsHub/bug/basic_is_not_null
Browse files Browse the repository at this point in the history
Bug: Fix not working very basic .is_not_null() query
  • Loading branch information
kbolashev authored Dec 19, 2024
2 parents 03d1d48 + 2c3e990 commit 52b56c6
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 2 deletions.
11 changes: 9 additions & 2 deletions dagshub/data_engine/model/query.py
Original file line number Diff line number Diff line change
Expand Up @@ -151,8 +151,15 @@ def compose(self, op: str, other: Optional[Union[str, int, float, "QueryFilterTr
# Negation in the operation - prepend a not node before the current node
tree = self._operand_tree
parent_id = tree.parent(node.identifier)
not_node = tree.create_node("not", parent=parent_id)
tree.move_node(node.identifier, not_node.identifier)
if parent_id is None:
# Root node - need to recreate a new tree with the not node as the top node
new_tree = Tree()
not_node = new_tree.create_node("not")
new_tree.paste(not_node.identifier, self._operand_tree)
self._operand_tree = new_tree
else:
not_node = tree.create_node("not", parent=parent_id)
tree.move_node(node.identifier, not_node.identifier)
op = op[1:]
node.tag = op
node.data.update({"value": other})
Expand Down
8 changes: 8 additions & 0 deletions tests/data_engine/test_querying.py
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,14 @@ def test_isnull_deserialization(ds):
assert queried.get_query().filter.serialize() == deserialized.serialize()


def test_is_not_null_serialization(ds):
add_string_fields(ds, "col1")
queried = ds["col1"].is_not_null()
expected = {"filter": {"key": "col1", "value": "", "valueType": "STRING", "comparator": "IS_NULL"}, "not": True}

assert queried.get_query().filter.serialize() == expected


def test_isnull_raises_not_on_field(ds):
with pytest.raises(RuntimeError):
ds.is_null()
Expand Down

0 comments on commit 52b56c6

Please sign in to comment.