alamb commented on code in PR #14119: URL: https://github.com/apache/datafusion/pull/14119#discussion_r1925978743
########## datafusion/functions/src/string/starts_with.rs: ########## @@ -98,6 +99,48 @@ impl ScalarUDFImpl for StartsWithFunc { } } + fn simplify( + &self, + args: Vec<Expr>, + _info: &dyn SimplifyInfo, + ) -> Result<ExprSimplifyResult> { + if let Expr::Literal(scalar_value) = &args[1] { + // Convert starts_with(col, 'prefix') to col LIKE 'prefix%' with proper escaping Review Comment: I double checked the escaping logic and I think this looks good to me. ########## datafusion/sqllogictest/test_files/string/string_view.slt: ########## @@ -344,7 +344,7 @@ EXPLAIN SELECT FROM test; ---- logical_plan -01)Projection: starts_with(test.column1_utf8view, Utf8View("äöüß")) AS c1, starts_with(test.column1_utf8view, Utf8View("")) AS c2, starts_with(test.column1_utf8view, Utf8View(NULL)) AS c3, starts_with(Utf8View(NULL), test.column1_utf8view) AS c4 +01)Projection: test.column1_utf8view LIKE Utf8View("äöüß%") AS c1, CASE test.column1_utf8view IS NOT NULL WHEN Boolean(true) THEN Boolean(true) END AS c2, starts_with(test.column1_utf8view, Utf8View(NULL)) AS c3, starts_with(Utf8View(NULL), test.column1_utf8view) AS c4 Review Comment: this is actually pretty cool -- it figured out that `STARTS_WITH(column1_utf8view, '') as c2,` is true if `column1_utf8view` is NOT NULL -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org