Skip to content

Commit

Permalink
remove faulty logic, merge conditions
Browse files Browse the repository at this point in the history
  • Loading branch information
adriangb committed Nov 4, 2024
1 parent 6c847fa commit 99b54be
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,21 +1474,17 @@ impl<'a, S: SimplifyInfo> TreeNodeRewriter for Simplifier<'a, S> {
if let Expr::Literal(ScalarValue::Utf8(Some(pattern_str))) =
like_expr.pattern.as_ref()
{
if !is_null(&like_expr.expr) && pattern_str == "%" {
Transformed::yes(lit(!like_expr.negated))
} else if !pattern_str.contains(['%', '_'].as_ref()) {
if !pattern_str.contains(['%', '_'].as_ref()) && like_expr.escape_char.is_none() {
// If the pattern does not contain any wildcards, we can simplify the like expression to an equality expression
if like_expr.escape_char.is_some() {
// TODO: handle escape characters
// These currently aren't anywhere else in DataFusion
Transformed::no(expr)
} else {
Transformed::yes(Expr::BinaryExpr(BinaryExpr {
left: like_expr.expr.clone(),
op: if like_expr.negated { NotEq } else { Eq },
right: like_expr.pattern.clone(),
}))
}

// TODO: handle escape characters
// These currently aren't anywhere else in DataFusion

Transformed::yes(Expr::BinaryExpr(BinaryExpr {
left: like_expr.expr.clone(),
op: if like_expr.negated { NotEq } else { Eq },
right: like_expr.pattern.clone(),
}))
} else {
Transformed::no(expr)
}
Expand Down

0 comments on commit 99b54be

Please sign in to comment.