Skip to content

Commit 8ced4a4

Browse files
committed
fix pattern matching order and adjust tests
1 parent 1ed1904 commit 8ced4a4

File tree

1 file changed

+23
-32
lines changed

1 file changed

+23
-32
lines changed

datafusion/sql/src/unparser/expr.rs

Lines changed: 23 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -261,32 +261,20 @@ impl Unparser<'_> {
261261
uses_odbc_syntax: false,
262262
}))
263263
}
264-
Expr::Like(Like {
264+
Expr::SimilarTo(Like {
265265
negated,
266266
expr,
267267
pattern,
268268
escape_char,
269-
case_insensitive,
270-
}) => {
271-
if *case_insensitive {
272-
Ok(ast::Expr::ILike {
273-
negated: *negated,
274-
expr: Box::new(self.expr_to_sql_inner(expr)?),
275-
pattern: Box::new(self.expr_to_sql_inner(pattern)?),
276-
escape_char: escape_char.map(|c| c.to_string()),
277-
any: false,
278-
})
279-
} else {
280-
Ok(ast::Expr::Like {
281-
negated: *negated,
282-
expr: Box::new(self.expr_to_sql_inner(expr)?),
283-
pattern: Box::new(self.expr_to_sql_inner(pattern)?),
284-
escape_char: escape_char.map(|c| c.to_string()),
285-
any: false,
286-
})
287-
}
288-
}
289-
Expr::SimilarTo(Like {
269+
case_insensitive: _,
270+
}) => Ok(ast::Expr::Like {
271+
negated: *negated,
272+
expr: Box::new(self.expr_to_sql_inner(expr)?),
273+
pattern: Box::new(self.expr_to_sql_inner(pattern)?),
274+
escape_char: escape_char.map(|c| c.to_string()),
275+
any: false,
276+
}),
277+
Expr::Like(Like {
290278
negated,
291279
expr,
292280
pattern,
@@ -1823,22 +1811,22 @@ mod tests {
18231811
r#"dummy_udf(a, b) IS NOT NULL"#,
18241812
),
18251813
(
1826-
Expr::Like(Like {
1827-
negated: true,
1814+
Expr::SimilarTo(Like {
1815+
negated: false,
18281816
expr: Box::new(col("a")),
18291817
pattern: Box::new(lit("foo")),
18301818
escape_char: Some('o'),
18311819
case_insensitive: false,
18321820
}),
1833-
r#"a NOT LIKE 'foo' ESCAPE 'o'"#,
1821+
r#"a LIKE 'foo' ESCAPE 'o'"#,
18341822
),
18351823
(
18361824
Expr::SimilarTo(Like {
18371825
negated: false,
18381826
expr: Box::new(col("a")),
18391827
pattern: Box::new(lit("foo")),
18401828
escape_char: Some('o'),
1841-
case_insensitive: false,
1829+
case_insensitive: true,
18421830
}),
18431831
r#"a LIKE 'foo' ESCAPE 'o'"#,
18441832
),
@@ -1848,19 +1836,19 @@ mod tests {
18481836
expr: Box::new(col("a")),
18491837
pattern: Box::new(lit("foo")),
18501838
escape_char: Some('o'),
1851-
case_insensitive: true,
1839+
case_insensitive: false,
18521840
}),
1853-
r#"a NOT ILIKE 'foo' ESCAPE 'o'"#,
1841+
r#"a NOT LIKE 'foo' ESCAPE 'o'"#,
18541842
),
18551843
(
1856-
Expr::SimilarTo(Like {
1857-
negated: false,
1844+
Expr::Like(Like {
1845+
negated: true,
18581846
expr: Box::new(col("a")),
18591847
pattern: Box::new(lit("foo")),
18601848
escape_char: Some('o'),
18611849
case_insensitive: true,
18621850
}),
1863-
r#"a ILIKE 'foo' ESCAPE 'o'"#,
1851+
r#"a NOT ILIKE 'foo' ESCAPE 'o'"#,
18641852
),
18651853
(
18661854
Expr::Literal(ScalarValue::Date64(Some(0))),
@@ -2651,7 +2639,10 @@ mod tests {
26512639
(&mysql_dialect, "DATETIME"),
26522640
] {
26532641
let unparser = Unparser::new(dialect);
2654-
let expr = Expr::Literal(ScalarValue::TimestampMillisecond(Some(1738285549123), None));
2642+
let expr = Expr::Literal(ScalarValue::TimestampMillisecond(
2643+
Some(1738285549123),
2644+
None,
2645+
));
26552646
let ast = unparser.expr_to_sql(&expr)?;
26562647

26572648
let actual = format!("{}", ast);

0 commit comments

Comments
 (0)