jaimeferj commented on code in PR #2561:
URL: https://github.com/apache/iceberg-python/pull/2561#discussion_r2440355085
##########
pyiceberg/expressions/__init__.py:
##########
@@ -743,12 +750,52 @@ def as_bound(self) -> Type[BoundNotIn[L]]:
return BoundNotIn[L]
-class LiteralPredicate(UnboundPredicate[L], ABC):
- literal: Literal[L]
+class LiteralPredicate(IcebergBaseModel, UnboundPredicate[L], ABC):
+ type: TypingLiteral["lt", "lt-eq", "gt", "gt-eq", "eq", "not-eq",
"starts-with", "not-starts-with"] = Field(alias="type")
+ term: UnboundTerm[Any]
+ value: Literal[L] = Field(alias="literal", serialization_alias="value")
+
+ model_config = ConfigDict(populate_by_name=True, frozen=True,
arbitrary_types_allowed=True)
+
+ def __init__(
+ self,
+ term: Union[str, UnboundTerm[Any], BoundReference[Any]],
+ literal: Union[L, Literal[L], None] = None,
+ **data: Any,
+ ) -> None: # pylint: disable=W0621
+ extra = dict(data)
+
+ literal_candidates = []
+ if literal is not None:
+ literal_candidates.append(literal)
+ if "literal" in extra:
+ literal_candidates.append(extra.pop("literal"))
+ if "value" in extra:
+ literal_candidates.append(extra.pop("value"))
+
+ literal_candidates = [candidate for candidate in literal_candidates if
candidate is not None]
+
+ if not literal_candidates:
+ raise TypeError("LiteralPredicate requires a literal or value
argument")
+ if len(literal_candidates) > 1:
+ raise TypeError("literal/value provided multiple times")
+
+ init = cast("Callable[..., None]", IcebergBaseModel.__init__)
+ init(self, term=_to_unbound_term(term),
literal=_to_literal(literal_candidates[0]), **extra)
+
+ @field_validator("term", mode="before")
+ @classmethod
+ def _convert_term(cls, value: Any) -> UnboundTerm[Any]:
+ return _to_unbound_term(value)
+
+ @field_validator("value", mode="before")
+ @classmethod
+ def _convert_value(cls, value: Any) -> Literal[Any]:
+ return _to_literal(value)
Review Comment:
If we are testing with BoundedReferences why not make the class allow to
accept them?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]