Skip to content
Open
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
9 changes: 8 additions & 1 deletion pyiceberg/expressions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -259,12 +259,18 @@ def as_bound(self) -> Type[BoundReference[L]]:
return BoundReference[L]


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

model_config = ConfigDict(arbitrary_types_allowed=True, frozen=False)

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

def __init__(self, left: BooleanExpression, right: BooleanExpression, *rest: BooleanExpression) -> None:
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 @@ -276,6 +282,7 @@ def __new__(cls, left: BooleanExpression, right: BooleanExpression, *rest: Boole
return left
else:
obj = super().__new__(cls)
obj.__pydantic_fields_set__ = set()
obj.left = left
obj.right = right
return obj
Expand Down
8 changes: 8 additions & 0 deletions tests/table/test_partitioning.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@

import pytest

from pyiceberg.expressions import And, EqualTo
from pyiceberg.partitioning import UNPARTITIONED_PARTITION_SPEC, PartitionField, PartitionSpec
from pyiceberg.schema import Schema
from pyiceberg.transforms import (
Expand Down Expand Up @@ -125,6 +126,13 @@ def test_serialize_partition_spec() -> None:
)


def test_serialize_and_expression() -> None:
expr = And(EqualTo("foo", 1), EqualTo("bar", 2))
assert expr.model_dump_json(by_alias=True) == (
'{"type":"and","left":{"type":"equal_to","term":"foo","literal":1},"right":{"type":"equal_to","term":"bar","literal":2}}'
)


def test_deserialize_unpartition_spec() -> None:
json_partition_spec = """{"spec-id":0,"fields":[]}"""
spec = PartitionSpec.model_validate_json(json_partition_spec)
Expand Down
Loading