Fokko commented on code in PR #6247: URL: https://github.com/apache/iceberg/pull/6247#discussion_r1033226610
########## 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: Ah, I see, I was missing this part: https://github.com/apache/iceberg/blob/master/api/src/main/java/org/apache/iceberg/expressions/Projections.java#L183-L185 -- 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-unsubscr...@iceberg.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: issues-unsubscr...@iceberg.apache.org For additional commands, e-mail: issues-h...@iceberg.apache.org