samredai commented on code in PR #4466:
URL: https://github.com/apache/iceberg/pull/4466#discussion_r851553371


##########
python/src/iceberg/expressions/base.py:
##########
@@ -122,3 +125,139 @@ def __le__(self, other):
 
     def __ge__(self, other):
         return self.value >= other.value
+
+
+class BooleanExpression(ABC):
+    """base class for all boolean expressions"""
+
+    @abstractmethod
+    def __invert__(self) -> "BooleanExpression":
+        ...
+
+
+class And(BooleanExpression):
+    """AND operation expression - logical conjunction"""
+
+    def __new__(cls, left: BooleanExpression, right: BooleanExpression, *rest: 
BooleanExpression):
+        if rest:
+            return reduce(And, (left, right, *rest))
+        if left is AlwaysFalse() or right is AlwaysFalse():
+            return AlwaysFalse()
+        elif left is AlwaysTrue():
+            return right
+        elif right is AlwaysTrue():
+            return left
+        return super().__new__(cls)
+
+    def __init__(
+        self,
+        left: BooleanExpression,
+        right: BooleanExpression,
+        *rest: BooleanExpression,
+    ):
+        if not rest:
+            self.left = left
+            self.right = right

Review Comment:
   I do think this could use some doc-strings describing this behavior though. 
Specifically mentioning \_\_new\_\_
   ```
       """AND operation expression - logical conjunction
   
       Args:
           left(BooleanExpression): The left hand boolean expression
           right(BooleanExpression): The right hand boolean expression
           *rest(BooleanExpression): Additional boolean expressions to fold 
into the AND expression
   
       Note:
           Additional boolean expressions provided to `rest` will be 
folded/reduced to create an object
           with only `left` and `right` specified (see  the `__new__` 
constructor) . For example,
           And(a, b, c) wil result in the equivalent of And(And(a, b), c).
       """
   ```
   Once predicates are added we could include an `Example:` section here too 
without failing the pydoc tests.



-- 
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]

Reply via email to