Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
11 changes: 8 additions & 3 deletions pyiceberg/expressions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -237,12 +237,19 @@ def as_bound(self) -> type[BoundReference]:
return BoundReference


class And(BooleanExpression):
class And(IcebergBaseModel, BooleanExpression):
"""AND operation expression - logical conjunction."""

model_config = ConfigDict(arbitrary_types_allowed=True)

type: TypingLiteral["and"] = Field(default="and", alias="type")
left: BooleanExpression
right: BooleanExpression

def __init__(self, left: BooleanExpression, right: BooleanExpression, *rest: BooleanExpression) -> None:
if isinstance(self, And) and not hasattr(self, "left") and not hasattr(self, "right"):
super().__init__(left=left, right=right)

def __new__(cls, left: BooleanExpression, right: BooleanExpression, *rest: BooleanExpression) -> BooleanExpression: # type: ignore
if rest:
return _build_balanced_tree(And, (left, right, *rest))
Expand All @@ -254,8 +261,6 @@ def __new__(cls, left: BooleanExpression, right: BooleanExpression, *rest: Boole
return left
else:
obj = super().__new__(cls)
obj.left = left
obj.right = right
return obj

def __eq__(self, other: Any) -> bool:
Expand Down
9 changes: 9 additions & 0 deletions tests/expressions/test_expressions.py
Original file line number Diff line number Diff line change
Expand Up @@ -725,6 +725,15 @@ def test_and() -> None:
null & "abc"


def test_and_serialization() -> None:
expr = And(EqualTo("x", 1), GreaterThan("y", 2))

assert (
expr.model_dump_json()
== '{"type":"and","left":{"term":"x","type":"eq","value":1},"right":{"term":"y","type":"gt","value":2}}'
)


def test_or() -> None:
null = IsNull(Reference("a"))
nan = IsNaN(Reference("b"))
Expand Down