sdd commented on code in PR #231: URL: https://github.com/apache/iceberg-rust/pull/231#discussion_r1517231867
########## crates/iceberg/src/expr/predicate.rs: ########## @@ -172,6 +228,146 @@ pub enum Predicate { Set(SetExpression<Reference>), } +impl Bind for Predicate { + type Bound = BoundPredicate; + + fn bind(self, schema: SchemaRef, case_sensitive: bool) -> Result<BoundPredicate> { + match self { + Predicate::And(expr) => { + let bound_expr = expr.bind(schema, case_sensitive)?; + + let [left, right] = bound_expr.inputs; + Ok(match (left, right) { + (_, r) if matches!(&*r, &BoundPredicate::AlwaysFalse) => { + BoundPredicate::AlwaysFalse + } + (l, _) if matches!(&*l, &BoundPredicate::AlwaysFalse) => { + BoundPredicate::AlwaysFalse + } + (left, r) if matches!(&*r, &BoundPredicate::AlwaysTrue) => *left, + (l, right) if matches!(&*l, &BoundPredicate::AlwaysTrue) => *right, + (left, right) => BoundPredicate::And(LogicalExpression::new([left, right])), + }) + } + Predicate::Not(expr) => { + let bound_expr = expr.bind(schema, case_sensitive)?; + let [inner] = bound_expr.inputs; + Ok(match inner { + e if matches!(&*e, &BoundPredicate::AlwaysTrue) => BoundPredicate::AlwaysFalse, + e if matches!(&*e, &BoundPredicate::AlwaysFalse) => BoundPredicate::AlwaysTrue, + e => BoundPredicate::Not(LogicalExpression::new([e])), Review Comment: You could use `negate()` here to do `Not` elimination :-) -- 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