Skip to content

Commit 7e8189a

Browse files
committed
feat: make and expression serializable
1 parent 369cbe3 commit 7e8189a

File tree

3 files changed

+10
-12
lines changed

3 files changed

+10
-12
lines changed

pyiceberg/expressions/__init__.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -261,9 +261,6 @@ def __new__(cls, left: BooleanExpression, right: BooleanExpression, *rest: Boole
261261
return left
262262
else:
263263
obj = super().__new__(cls)
264-
obj.__pydantic_fields_set__ = set()
265-
obj.left = left
266-
obj.right = right
267264
return obj
268265

269266
def __eq__(self, other: Any) -> bool:
@@ -272,7 +269,7 @@ def __eq__(self, other: Any) -> bool:
272269

273270
def __str__(self) -> str:
274271
"""Return the string representation of the And class."""
275-
return f"{str(self.__class__.__name__)}(left={repr(self.left)}, right={repr(self.right)})"
272+
return f"And(left={str(self.left)}, right={str(self.right)})"
276273

277274
def __repr__(self) -> str:
278275
"""Return the string representation of the And class."""

tests/expressions/test_expressions.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -725,6 +725,15 @@ def test_and() -> None:
725725
null & "abc"
726726

727727

728+
def test_and_serialization() -> None:
729+
expr = And(EqualTo("x", 1), GreaterThan("y", 2))
730+
731+
assert (
732+
expr.model_dump_json()
733+
== '{"type":"and","left":{"term":"x","type":"eq","value":1},"right":{"term":"y","type":"gt","value":2}}'
734+
)
735+
736+
728737
def test_or() -> None:
729738
null = IsNull(Reference("a"))
730739
nan = IsNaN(Reference("b"))

tests/table/test_partitioning.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@
2121

2222
import pytest
2323

24-
from pyiceberg.expressions import And, EqualTo
2524
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionField, PartitionSpec
2625
from pyiceberg.schema import Schema
2726
from pyiceberg.transforms import (
@@ -126,13 +125,6 @@ def test_serialize_partition_spec() -> None:
126125
)
127126

128127

129-
def test_serialize_and_expression() -> None:
130-
expr = And(EqualTo("foo", 1), EqualTo("bar", 2))
131-
assert expr.model_dump_json(by_alias=True) == (
132-
'{"type":"and","left":{"type":"equal_to","term":"foo","literal":1},"right":{"type":"equal_to","term":"bar","literal":2}}'
133-
)
134-
135-
136128
def test_deserialize_unpartition_spec() -> None:
137129
json_partition_spec = """{"spec-id":0,"fields":[]}"""
138130
spec = PartitionSpec.model_validate_json(json_partition_spec)

0 commit comments

Comments
 (0)