1717
1818from __future__ import annotations
1919
20+ import typing
2021from abc import ABC , abstractmethod
2122from functools import cached_property
2223from typing import (
3233 Union ,
3334)
3435
36+ from pydantic import ConfigDict , Field , field_serializer
37+
3538from pyiceberg .expressions .literals import (
3639 AboveMax ,
3740 BelowMin ,
3841 Literal ,
3942 literal ,
4043)
4144from pyiceberg .schema import Accessor , Schema
42- from pyiceberg .typedef import IcebergRootModel , L , StructProtocol
45+ from pyiceberg .typedef import IcebergBaseModel , IcebergRootModel , L , StructProtocol
4346from pyiceberg .types import DoubleType , FloatType , NestedField
4447from pyiceberg .utils .singleton import Singleton
4548
@@ -290,12 +293,18 @@ def __getnewargs__(self) -> Tuple[BooleanExpression, BooleanExpression]:
290293 return (self .left , self .right )
291294
292295
293- class Or (BooleanExpression ):
296+ class Or (IcebergBaseModel , BooleanExpression ):
294297 """OR operation expression - logical disjunction."""
295298
299+ model_config = ConfigDict (arbitrary_types_allowed = True )
300+
301+ type : str = Field (default = "or" , repr = False )
296302 left : BooleanExpression
297303 right : BooleanExpression
298304
305+ def __init__ (self , left : typing .Union [BooleanExpression , Or ], right : typing .Union [BooleanExpression , Or ], * rest : Any ):
306+ return super ().__init__ (left = left , right = right )
307+
299308 def __new__ (cls , left : BooleanExpression , right : BooleanExpression , * rest : BooleanExpression ) -> BooleanExpression : # type: ignore
300309 if rest :
301310 return _build_balanced_tree (Or , (left , right , * rest ))
@@ -307,10 +316,24 @@ def __new__(cls, left: BooleanExpression, right: BooleanExpression, *rest: Boole
307316 return left
308317 else :
309318 obj = super ().__new__ (cls )
310- obj .left = left
311- obj .right = right
312319 return obj
313320
321+ @field_serializer ("left" )
322+ def ser_left (self , left : BooleanExpression ) -> str :
323+ if isinstance (left , IcebergRootModel ):
324+ return left .root
325+ return str (left )
326+
327+ @field_serializer ("right" )
328+ def ser_right (self , right : BooleanExpression ) -> str :
329+ if isinstance (right , IcebergRootModel ):
330+ return right .root
331+ return str (right )
332+
333+ def __str__ (self ) -> str :
334+ """Return the string representation of the Or class."""
335+ return f"{ str (self .__class__ .__name__ )} (left={ repr (self .left )} , right={ repr (self .right )} )"
336+
314337 def __eq__ (self , other : Any ) -> bool :
315338 """Return the equality of two instances of the Or class."""
316339 return self .left == other .left and self .right == other .right if isinstance (other , Or ) else False
0 commit comments