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


##########
python/pyiceberg/expressions/visitors.py:
##########
@@ -691,3 +692,68 @@ def manifest_evaluator(
     partition_schema = Schema(*partition_type.fields)
     evaluator = _ManifestEvalVisitor(partition_schema, partition_filter, 
case_sensitive)
     return evaluator.eval
+
+
+class ProjectionEvaluator(BooleanExpressionVisitor[BooleanExpression], ABC):
+    schema: Schema
+    spec: PartitionSpec
+    case_sensitive: bool
+
+    def __init__(self, schema: Schema, spec: PartitionSpec, case_sensitive: 
bool):
+        self.schema = schema
+        self.spec = spec
+        self.case_sensitive = case_sensitive
+
+    def project(self, expr: BooleanExpression) -> BooleanExpression:
+        #  projections assume that there are no NOT nodes in the expression 
tree. to ensure that this
+        #  is the case, the expression is rewritten to push all NOT nodes down 
to the expression
+        #  leaf nodes.
+        #  this is necessary to ensure that the default expression returned 
when a predicate can't be
+        #  projected is correct.
+        return rewrite_not(expr)
+
+    def visit_true(self) -> BooleanExpression:
+        return AlwaysTrue()
+
+    def visit_false(self) -> BooleanExpression:
+        return AlwaysFalse()
+
+    def visit_not(self, child_result: BooleanExpression) -> BooleanExpression:
+        raise NotImplementedError(f"Should not happen as the expression is 
rewritten: {child_result}")
+
+    def visit_and(self, left_result: BooleanExpression, right_result: 
BooleanExpression) -> BooleanExpression:
+        return And(left_result, right_result)
+
+    def visit_or(self, left_result: BooleanExpression, right_result: 
BooleanExpression) -> BooleanExpression:
+        return Or(left_result, right_result)
+
+    def visit_unbound_predicate(self, predicate: UnboundPredicate[L]) -> 
BooleanExpression:
+        partition_type = self.spec.partition_type(self.schema)
+        partition_schema = Schema(*partition_type.fields)
+        return predicate.bind(schema=partition_schema, 
case_sensitive=self.case_sensitive)

Review Comment:
   In the Java version, this doesn't just bind the predicate and return it. It 
binds and then if the result was a predicate (i.e. not `AlwaysTrue()`) then it 
runs `visit_bound_predicate` on the result.



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