This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-datafusion.git
The following commit(s) were added to refs/heads/main by this push:
new 0b11d143ec expr like to sql (#9805)
0b11d143ec is described below
commit 0b11d143ec77aeac0207bd20f790b21790397767
Author: Alex Huang <[email protected]>
AuthorDate: Wed Mar 27 11:00:29 2024 +0800
expr like to sql (#9805)
---
datafusion/sql/src/unparser/expr.rs | 25 +++++++++++++++++++------
1 file changed, 19 insertions(+), 6 deletions(-)
diff --git a/datafusion/sql/src/unparser/expr.rs
b/datafusion/sql/src/unparser/expr.rs
index 550b02cea7..8610269bdb 100644
--- a/datafusion/sql/src/unparser/expr.rs
+++ b/datafusion/sql/src/unparser/expr.rs
@@ -175,14 +175,17 @@ impl Unparser<'_> {
not_impl_err!("Unsupported expression: {expr:?}")
}
Expr::Like(Like {
- negated: _,
+ negated,
expr,
- pattern: _,
- escape_char: _,
+ pattern,
+ escape_char,
case_insensitive: _,
- }) => {
- not_impl_err!("Unsupported expression: {expr:?}")
- }
+ }) => Ok(ast::Expr::Like {
+ negated: *negated,
+ expr: Box::new(self.expr_to_sql(expr)?),
+ pattern: Box::new(self.expr_to_sql(pattern)?),
+ escape_char: *escape_char,
+ }),
Expr::AggregateFunction(agg) => {
let func_name = if let
AggregateFunctionDefinition::BuiltIn(built_in) =
&agg.func_def
@@ -706,6 +709,16 @@ mod tests {
ScalarUDF::new_from_impl(DummyUDF::new()).call(vec![col("a"),
col("b")]),
r#"dummy_udf("a", "b")"#,
),
+ (
+ Expr::Like(Like {
+ negated: true,
+ expr: Box::new(col("a")),
+ pattern: Box::new(lit("foo")),
+ escape_char: Some('o'),
+ case_insensitive: true,
+ }),
+ r#""a" NOT LIKE 'foo' ESCAPE 'o'"#,
+ ),
(
Expr::Literal(ScalarValue::Date64(Some(0))),
r#"CAST('1970-01-01 00:00:00' AS DATETIME)"#,