Skip to content

Commit 92d1880

Browse files
committed
moar
1 parent 0293505 commit 92d1880

File tree

1 file changed

+8
-8
lines changed

1 file changed

+8
-8
lines changed

datafusion/src/optimizer/simplify_expressions.rs

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,8 @@ use crate::{error::Result, logical_plan::Operator};
4545
///
4646
pub struct SimplifyExpressions {}
4747

48+
/// returns true if `needle` is found in a chain of AND/OR exprs
49+
/// (A AND B) AND C
4850
fn expr_contains(expr: &Expr, needle: &Expr) -> bool {
4951
match expr {
5052
Expr::BinaryExpr {
@@ -61,7 +63,7 @@ fn expr_contains(expr: &Expr, needle: &Expr) -> bool {
6163
}
6264
}
6365

64-
fn as_binary_expr(expr: &Expr) -> Option<&Expr> {
66+
fn as_binary_expr_old(expr: &Expr) -> Option<&Expr> {
6567
match expr {
6668
Expr::BinaryExpr { .. } => Some(expr),
6769
_ => None,
@@ -185,7 +187,7 @@ fn old_simplify(expr: &Expr) -> Expr {
185187
left,
186188
op: Operator::Or,
187189
right,
188-
} if expr_contains(left, right) => as_binary_expr(left)
190+
} if expr_contains(left, right) => as_binary_expr_old(left)
189191
.map(|x| match x {
190192
Expr::BinaryExpr {
191193
left: _,
@@ -204,7 +206,7 @@ fn old_simplify(expr: &Expr) -> Expr {
204206
left,
205207
op: Operator::Or,
206208
right,
207-
} if expr_contains(right, left) => as_binary_expr(right)
209+
} if expr_contains(right, left) => as_binary_expr_old(right)
208210
.map(|x| match x {
209211
Expr::BinaryExpr {
210212
left: _,
@@ -223,7 +225,7 @@ fn old_simplify(expr: &Expr) -> Expr {
223225
left,
224226
op: Operator::And,
225227
right,
226-
} if expr_contains(left, right) => as_binary_expr(left)
228+
} if expr_contains(left, right) => as_binary_expr_old(left)
227229
.map(|x| match x {
228230
Expr::BinaryExpr {
229231
left: _,
@@ -242,7 +244,7 @@ fn old_simplify(expr: &Expr) -> Expr {
242244
left,
243245
op: Operator::And,
244246
right,
245-
} if expr_contains(right, left) => as_binary_expr(right)
247+
} if expr_contains(right, left) => as_binary_expr_old(right)
246248
.map(|x| match x {
247249
Expr::BinaryExpr {
248250
left: _,
@@ -695,7 +697,7 @@ impl<'a> ExprRewriter for Simplifier<'a> {
695697
}
696698
(left, Literal(Boolean(b))) if self.is_boolean_type(&left) => {
697699
Self::boolean_folding_for_or(b, left, false)
698-
},
700+
}
699701
// A OR A --> A
700702
(left, right) if left == right => left,
701703
(left, right) => BinaryExpr {
@@ -724,8 +726,6 @@ impl<'a> ExprRewriter for Simplifier<'a> {
724726
Operator::Divide if is_one(&right) => *left,
725727
Operator::Divide if left == right && is_null(&left) => *left,
726728
Operator::Divide if left == right => lit(1),
727-
728-
729729
_ => BinaryExpr { left, op, right },
730730
},
731731
// Not(Not(expr)) --> expr

0 commit comments

Comments
 (0)