Skip to content

Commit

Permalink
expr like to sql (#9805)
Browse files Browse the repository at this point in the history
  • Loading branch information
Weijun-H authored Mar 27, 2024
1 parent e337832 commit 0b11d14
Showing 1 changed file with 19 additions and 6 deletions.
25 changes: 19 additions & 6 deletions datafusion/sql/src/unparser/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)"#,
Expand Down

0 comments on commit 0b11d14

Please sign in to comment.