4242from pyiceberg .typedef import L , StructProtocol
4343from pyiceberg .types import DoubleType , FloatType , NestedField
4444from pyiceberg .utils .singleton import Singleton
45+ from pyiceberg .utils .pydantic import IcebergBaseModel
46+ from pydantic import Field
4547
4648
4749def _to_unbound_term (term : Union [str , UnboundTerm [Any ]]) -> UnboundTerm [Any ]:
@@ -559,12 +561,19 @@ def as_bound(self) -> Type[BoundNotNaN[L]]:
559561 return BoundNotNaN [L ]
560562
561563
562- class SetPredicate (UnboundPredicate [L ], ABC ):
563- literals : Set [Literal [L ]]
564+ class SetPredicate (UnboundPredicate [L ], IcebergBaseModel , ABC ):
565+ type : str = Field (default = "in" , alias = "type" )
566+ term : str
567+ value : list [Any ]
564568
565569 def __init__ (self , term : Union [str , UnboundTerm [Any ]], literals : Union [Iterable [L ], Iterable [Literal [L ]]]):
566- super ().__init__ (term )
567- self .literals = _to_literal_set (literals )
570+ # Convert term to string for serialization
571+ term_str = term .name if isinstance (term , Reference ) else str (term )
572+ literals_set = _to_literal_set (literals )
573+ value_list = [lit .value for lit in literals_set ]
574+ super ().__init__ (term = term_str , value = value_list )
575+ self .literals = literals_set
576+ self .term_obj = term
568577
569578 def bind (self , schema : Schema , case_sensitive : bool = True ) -> BoundSetPredicate [L ]:
570579 bound_term = self .term .bind (schema , case_sensitive )
@@ -676,6 +685,8 @@ def as_unbound(self) -> Type[NotIn[L]]:
676685
677686
678687class In (SetPredicate [L ]):
688+ type : str = Field (default = "in" , alias = "type" )
689+
679690 def __new__ ( # type: ignore # pylint: disable=W0221
680691 cls , term : Union [str , UnboundTerm [Any ]], literals : Union [Iterable [L ], Iterable [Literal [L ]]]
681692 ) -> BooleanExpression :
@@ -698,6 +709,8 @@ def as_bound(self) -> Type[BoundIn[L]]:
698709
699710
700711class NotIn (SetPredicate [L ], ABC ):
712+ type : str = Field (default = "not-in" , alias = "type" )
713+
701714 def __new__ ( # type: ignore # pylint: disable=W0221
702715 cls , term : Union [str , UnboundTerm [Any ]], literals : Union [Iterable [L ], Iterable [Literal [L ]]]
703716 ) -> BooleanExpression :
@@ -712,7 +725,7 @@ def __new__( # type: ignore # pylint: disable=W0221
712725
713726 def __invert__ (self ) -> In [L ]:
714727 """Transform the Expression into its negated version."""
715- return In [L ](self .term , self .literals )
728+ return In [L ](self .term , self ._literals )
716729
717730 @property
718731 def as_bound (self ) -> Type [BoundNotIn [L ]]:
0 commit comments