Skip to content

fix: fix rewrite_not to process complex nested not #1431

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 19, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 4 additions & 23 deletions crates/iceberg/src/expr/predicate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ use itertools::Itertools;
use serde::{Deserialize, Serialize};

use crate::error::Result;
use crate::expr::visitors::predicate_visitor::visit;
use crate::expr::visitors::rewrite_not::RewriteNotVisitor;
use crate::expr::{Bind, BoundReference, PredicateOperator, Reference};
use crate::spec::{Datum, PrimitiveLiteral, SchemaRef};
use crate::{Error, ErrorKind};
Expand Down Expand Up @@ -652,29 +654,8 @@ impl Predicate {
/// assert_eq!(&format!("{result}"), "a >= 5");
/// ```
pub fn rewrite_not(self) -> Predicate {
match self {
Predicate::And(expr) => {
let [left, right] = expr.inputs;
let new_left = Box::new(left.rewrite_not());
let new_right = Box::new(right.rewrite_not());
Predicate::And(LogicalExpression::new([new_left, new_right]))
}
Predicate::Or(expr) => {
let [left, right] = expr.inputs;
let new_left = Box::new(left.rewrite_not());
let new_right = Box::new(right.rewrite_not());
Predicate::Or(LogicalExpression::new([new_left, new_right]))
}
Predicate::Not(expr) => {
let [inner] = expr.inputs;
inner.negate()
}
Predicate::Unary(expr) => Predicate::Unary(expr),
Predicate::Binary(expr) => Predicate::Binary(expr),
Predicate::Set(expr) => Predicate::Set(expr),
Predicate::AlwaysTrue => Predicate::AlwaysTrue,
Predicate::AlwaysFalse => Predicate::AlwaysFalse,
}
visit(&mut RewriteNotVisitor::new(), &self)
.expect("RewriteNotVisitor guarantees always success")
}
}

Expand Down
2 changes: 2 additions & 0 deletions crates/iceberg/src/expr/visitors/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ pub(crate) mod inclusive_metrics_evaluator;
pub(crate) mod inclusive_projection;
pub(crate) mod manifest_evaluator;
pub(crate) mod page_index_evaluator;
pub(crate) mod predicate_visitor;
pub(crate) mod rewrite_not;
pub(crate) mod row_group_metrics_evaluator;
pub(crate) mod strict_metrics_evaluator;
pub(crate) mod strict_projection;
Loading
Loading