diff --git a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs index f410ab8190cf..7f7923a96f41 100644 --- a/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs +++ b/datafusion/optimizer/src/simplify_expressions/expr_simplifier.rs @@ -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) }