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


##########
python/pyiceberg/expressions/base.py:
##########
@@ -474,3 +474,77 @@ def visit_unbound_predicate(self, predicate) -> 
BooleanExpression:
 
     def visit_bound_predicate(self, predicate) -> BooleanExpression:
         raise TypeError(f"Found already bound predicate: {predicate}")
+
+
+class BoundBooleanExpressionVisitor(Generic[R], BooleanExpressionVisitor[R], 
ABC):
+    def visit_in(self, ref: BoundReference[T], literals: Tuple[Literal[T], 
...]) -> R:
+        """Visit the ref and literals from an In boolean expression
+
+        Args:
+            ref (BoundReference[T]): The ref used in the In boolean expression
+            literals (Tuple[Literal[T], ...]): The literals used in the In 
boolean expression
+
+        Raises:
+            NotImplementedError: If the concrete bound boolean expression 
visitor does not override this method
+
+        Returns:
+            R: The return type defined by the concrete bound boolean 
expression visitor
+        """
+        raise NotImplementedError(f"{type(self).__name__} does not support 
visiting In expressions")
+
+    def handle_non_reference(self, term: BoundTerm) -> R:
+        """Handle a non-reference value in this visitor
+
+        Visitors that specificially require references can use this method to 
return a default value for expressions with non-references.
+        The default implementation will throw a TypeError because the 
non-reference is not supported.
+
+        Args:
+            term (BoundTerm): a non-reference term such as a transform
+
+        Raises:
+            TypeError: when handle_non_reference is not implemented in the 
concrete visitor
+
+        Returns:
+            R: The return type defined by the concrete bound boolean 
expression visitor
+        """
+        raise TypeError(f"BoundExpressionVisitor does not support 
non-reference: {term}")
+
+    def visit_unbound_predicate(self, predicate: UnboundPredicate[T]):
+        """Visit an unbound predicate
+
+        Args:
+            predicate (UnboundPredicate[T]): An unbound predicate
+
+        Raises:
+            TypeError: This always raises since an unbound predicate is not 
expected in a bound boolean expression
+        """
+        raise TypeError(f"Not a bound predicate: {predicate}")
+
+    @singledispatchmethod

Review Comment:
   That's right, I forgot about the performance hit when using this. I replaced 
it with a simple if block that does an `isinstance` check.



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