From 0e939ed5c3d48d95b95ad99efee894341018a868 Mon Sep 17 00:00:00 2001 From: zhuliquan Date: Wed, 18 Sep 2024 20:52:15 +0800 Subject: [PATCH] feat: apply scalar_regex_match optimize to similar_to case --- datafusion/physical-expr/src/planner.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/datafusion/physical-expr/src/planner.rs b/datafusion/physical-expr/src/planner.rs index 3a60e0cfeb240..2bc9332d908e1 100644 --- a/datafusion/physical-expr/src/planner.rs +++ b/datafusion/physical-expr/src/planner.rs @@ -255,6 +255,23 @@ pub fn create_physical_expr( create_physical_expr(expr, input_dfschema, execution_props)?; let physical_pattern = create_physical_expr(pattern, input_dfschema, execution_props)?; + + if let Expr::Literal( + ScalarValue::Null + | ScalarValue::Utf8(_) + | ScalarValue::Utf8View(_) + | ScalarValue::LargeUtf8(_), + ) = pattern.as_ref() + { + // handle literal regexp pattern case to `ScalarRegexMatchExpr` + return scalar_regex_match( + *negated, + *case_insensitive, + physical_expr, + physical_pattern, + input_schema, + ); + } similar_to(*negated, *case_insensitive, physical_expr, physical_pattern) } Expr::Case(case) => {