Skip to content

Commit

Permalink
fix: Error in optimization for nested boolean expressions (#154)
Browse files Browse the repository at this point in the history
  • Loading branch information
waralexrom authored Apr 24, 2024
1 parent 2b1e701 commit 823422f
Showing 1 changed file with 12 additions and 2 deletions.
14 changes: 12 additions & 2 deletions datafusion/src/optimizer/simplify_expressions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,17 +35,27 @@ use crate::{error::Result, logical_plan::Operator};
pub struct SimplifyExpressions {}

fn expr_contains(expr: &Expr, needle: &Expr) -> bool {
// We turned off the recursion becouse it lead to wrong optimizations like b > 2 and ((b > 2 and a=1) or (a = 3)) -> b > 2
// expr == needle
match expr {
Expr::BinaryExpr {
left,
op: Operator::And,
right,
} => expr_contains(left, needle) || expr_contains(right, needle),
} => {
// We turned off the recursion becouse it lead to wrong optimizations like b > 2 and ((b > 2 and a=1) or (a = 3)) -> b > 2
left.as_ref() == needle || right.as_ref() == needle
//expr_contains(left, needle) || expr_contains(right, needle)
}
Expr::BinaryExpr {
left,
op: Operator::Or,
right,
} => expr_contains(left, needle) || expr_contains(right, needle),
} => {
// We turned off the recursion becouse it lead to wrong optimizations like b > 2 and ((b > 2 and a=1) or (a = 3)) -> b > 2
left.as_ref() == needle || right.as_ref() == needle
//expr_contains(left, needle) || expr_contains(right, needle)
}
_ => expr == needle,
}
}
Expand Down

0 comments on commit 823422f

Please sign in to comment.