You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@iceberg.apache.org by GitBox <gi...@apache.org> on 2022/07/25 19:23:27 UTC

[GitHub] [iceberg] rdblue commented on a diff in pull request #5258: More Python Expressions

rdblue commented on code in PR #5258:
URL: https://github.com/apache/iceberg/pull/5258#discussion_r929221621


##########
python/pyiceberg/expressions/base.py:
##########
@@ -169,16 +171,70 @@ def bind(self, schema: Schema, case_sensitive: bool) -> BoundReference[T]:
         return BoundReference(field=field, accessor=accessor)
 
 
-@dataclass(frozen=True)  # type: ignore[misc]
 class BoundPredicate(Bound[T], BooleanExpression):
-    term: BoundReference[T]
-    literals: Tuple[Literal[T], ...]
+    _term: BoundTerm[T]
+    _literals: tuple[Literal[T], ...]
+
+    def __init__(self, term: BoundTerm[T], *literals: Literal[T]):
+        self._term = term
+        self._literals = literals
+        self._validate_literals()
+
+    def _validate_literals(self):
+        if len(self.literals) != 1:
+            raise AttributeError(f"{self.__class__.__name__} must have exactly 1 literal.")
+
+    @property
+    def term(self) -> BoundTerm[T]:
+        return self._term
+
+    @property
+    def literals(self) -> tuple[Literal[T], ...]:
+        return self._literals
+
+    def __str__(self) -> str:
+        return f"{self.__class__.__name__}({str(self.term)}{self.literals and ', '+str(self.literals)})"

Review Comment:
   When I test this and `literals` is an empty list, I get `x[]` (where `x` is the term)



-- 
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: issues-unsubscribe@iceberg.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: issues-unsubscribe@iceberg.apache.org
For additional commands, e-mail: issues-help@iceberg.apache.org