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
11 changes: 10 additions & 1 deletion pyiceberg/expressions/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@
Union,
)

from pydantic import Field

from pyiceberg.expressions.literals import (
AboveMax,
BelowMin,
Expand Down Expand Up @@ -247,9 +249,10 @@ def as_bound(self) -> Type[BoundReference[L]]:
return BoundReference[L]


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

type: str = Field(default="and", alias="type")
left: BooleanExpression
right: BooleanExpression

Expand Down Expand Up @@ -289,6 +292,12 @@ def __getnewargs__(self) -> Tuple[BooleanExpression, BooleanExpression]:
"""Pickle the And class."""
return (self.left, self.right)

class Config:
"""Pydantic configuration for And expression serialization."""

arbitrary_types_allowed = True
json_encoders = {BooleanExpression: lambda v: v.model_dump(by_alias=True) if isinstance(v, IcebergBaseModel) else str(v)}


class Or(BooleanExpression):
"""OR operation expression - logical disjunction."""
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