Skip to content

Commit 81082c6

Browse files
committed
Make the CI happy
1 parent ca61255 commit 81082c6

File tree

1 file changed

+14
-29
lines changed

1 file changed

+14
-29
lines changed

pyiceberg/expressions/__init__.py

Lines changed: 14 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -20,10 +20,10 @@
2020
from abc import ABC, abstractmethod
2121
from collections.abc import Callable, Iterable, Sequence
2222
from functools import cached_property
23-
from typing import Annotated, Any, TypeAlias
23+
from typing import Any, TypeAlias
2424
from typing import Literal as TypingLiteral
2525

26-
from pydantic import ConfigDict, Discriminator, Field, Tag, model_validator
26+
from pydantic import ConfigDict, Field, SerializeAsAny, model_validator
2727
from pydantic_core.core_schema import ValidatorFunctionWrapHandler
2828

2929
from pyiceberg.expressions.literals import AboveMax, BelowMin, Literal, literal
@@ -73,6 +73,10 @@ def __or__(self, other: BooleanExpression) -> BooleanExpression:
7373
@classmethod
7474
def handle_primitive_type(cls, v: Any, handler: ValidatorFunctionWrapHandler) -> BooleanExpression:
7575
"""Apply custom deserialization logic before validation."""
76+
# Already a BooleanExpression? return as-is so we keep the concrete subclass.
77+
if isinstance(v, BooleanExpression):
78+
return v
79+
7680
# Handle different input formats
7781
if isinstance(v, bool):
7882
return AlwaysTrue() if v else AlwaysFalse()
@@ -123,6 +127,9 @@ def handle_primitive_type(cls, v: Any, handler: ValidatorFunctionWrapHandler) ->
123127
return handler(v)
124128

125129

130+
SerializableBooleanExpression: TypeAlias = SerializeAsAny["BooleanExpression"]
131+
132+
126133
def _build_balanced_tree(
127134
operator_: Callable[[BooleanExpression, BooleanExpression], BooleanExpression], items: Sequence[BooleanExpression]
128135
) -> BooleanExpression:
@@ -290,36 +297,14 @@ def as_bound(self) -> type[BoundReference]:
290297
return BoundReference
291298

292299

293-
Predicates: TypeAlias = Annotated[
294-
Annotated["IsNull", Tag("is-null")]
295-
| Annotated["NotNull", Tag("not-null")]
296-
| Annotated["IsNaN", Tag("is-nan")]
297-
| Annotated["NotNaN", Tag("not-nan")]
298-
| Annotated["EqualTo", Tag("eq")]
299-
| Annotated["NotEqualTo", Tag("not-eq")]
300-
| Annotated["LessThan", Tag("lt")]
301-
| Annotated["LessThanOrEqual", Tag("lt-eq")]
302-
| Annotated["GreaterThan", Tag("gt")]
303-
| Annotated["GreaterThanOrEqual", Tag("gt-eq")]
304-
| Annotated["StartsWith", Tag("starts-with")]
305-
| Annotated["NotStartsWith", Tag("not-starts-with")]
306-
| Annotated["In", Tag("in")]
307-
| Annotated["NotIn", Tag("not-in")]
308-
| Annotated["And", Tag("and")]
309-
| Annotated["Or", Tag("or")]
310-
| Annotated["Not", Tag("not")],
311-
Discriminator("type"),
312-
]
313-
314-
315300
class And(BooleanExpression):
316301
"""AND operation expression - logical conjunction."""
317302

318303
model_config = ConfigDict(arbitrary_types_allowed=True)
319304

320305
type: TypingLiteral["and"] = Field(default="and", alias="type")
321-
left: Predicates
322-
right: Predicates
306+
left: SerializableBooleanExpression = Field()
307+
right: SerializableBooleanExpression = Field()
323308

324309
def __init__(self, left: BooleanExpression, right: BooleanExpression, *rest: BooleanExpression, **_: Any) -> None:
325310
if isinstance(self, And) and not hasattr(self, "left") and not hasattr(self, "right"):
@@ -365,8 +350,8 @@ class Or(BooleanExpression):
365350
model_config = ConfigDict(arbitrary_types_allowed=True)
366351

367352
type: TypingLiteral["or"] = Field(default="or", alias="type")
368-
left: Predicates
369-
right: Predicates
353+
left: SerializableBooleanExpression = Field()
354+
right: SerializableBooleanExpression = Field()
370355

371356
def __init__(self, left: BooleanExpression, right: BooleanExpression, *rest: BooleanExpression) -> None:
372357
if isinstance(self, Or) and not hasattr(self, "left") and not hasattr(self, "right"):
@@ -412,7 +397,7 @@ class Not(BooleanExpression):
412397
model_config = ConfigDict(arbitrary_types_allowed=True)
413398

414399
type: TypingLiteral["not"] = Field(default="not")
415-
child: Predicates = Field()
400+
child: SerializableBooleanExpression = Field()
416401

417402
def __init__(self, child: BooleanExpression, **_: Any) -> None:
418403
super().__init__(child=child)

0 commit comments

Comments
 (0)