Skip to content

Commit dd534a8

Browse files
committed
Make And expression JSON serializable using Pydantic
1 parent f3e740f commit dd534a8

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

pyiceberg/expressions/__init__.py

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,8 +31,9 @@
3131
TypeVar,
3232
Union,
3333
)
34+
from typing import Literal as TypingLiteral
3435

35-
from pydantic import Field
36+
from pydantic import ConfigDict, Field
3637

3738
from pyiceberg.expressions.literals import (
3839
AboveMax,
@@ -249,13 +250,18 @@ def as_bound(self) -> Type[BoundReference[L]]:
249250
return BoundReference[L]
250251

251252

252-
class And(BooleanExpression, IcebergBaseModel):
253+
class And(IcebergBaseModel, BooleanExpression):
253254
"""AND operation expression - logical conjunction."""
254255

255-
type: str = Field(default="and", alias="type")
256+
model_config = ConfigDict(arbitrary_types_allowed=True)
257+
258+
type: TypingLiteral["and"] = Field(default="and", alias="type")
256259
left: BooleanExpression
257260
right: BooleanExpression
258261

262+
def __init__(self, left: BooleanExpression, right: BooleanExpression, *rest: BooleanExpression) -> None:
263+
super().__init__(left=left, right=right)
264+
259265
def __new__(cls, left: BooleanExpression, right: BooleanExpression, *rest: BooleanExpression) -> BooleanExpression: # type: ignore
260266
if rest:
261267
return _build_balanced_tree(And, (left, right, *rest))
@@ -292,12 +298,6 @@ def __getnewargs__(self) -> Tuple[BooleanExpression, BooleanExpression]:
292298
"""Pickle the And class."""
293299
return (self.left, self.right)
294300

295-
class Config:
296-
"""Pydantic configuration for And expression serialization."""
297-
298-
arbitrary_types_allowed = True
299-
json_encoders = {BooleanExpression: lambda v: v.model_dump(by_alias=True) if isinstance(v, IcebergBaseModel) else str(v)}
300-
301301

302302
class Or(BooleanExpression):
303303
"""OR operation expression - logical disjunction."""

0 commit comments

Comments
 (0)