Skip to content

Commit c00431c

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

File tree

1 file changed

+19
-31
lines changed

1 file changed

+19
-31
lines changed

datafusion/sql/src/unparser/expr.rs

Lines changed: 19 additions & 31 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,
@@ -1833,24 +1821,24 @@ mod tests {
18331821
r#"a NOT LIKE 'foo' ESCAPE 'o'"#,
18341822
),
18351823
(
1836-
Expr::SimilarTo(Like {
1837-
negated: false,
1824+
Expr::Like(Like {
1825+
negated: true,
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
}),
1843-
r#"a LIKE 'foo' ESCAPE 'o'"#,
1831+
r#"a NOT ILIKE 'foo' ESCAPE 'o'"#,
18441832
),
18451833
(
1846-
Expr::Like(Like {
1847-
negated: true,
1834+
Expr::SimilarTo(Like {
1835+
negated: false,
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 LIKE 'foo' ESCAPE 'o'"#,
18541842
),
18551843
(
18561844
Expr::SimilarTo(Like {
@@ -1860,7 +1848,7 @@ mod tests {
18601848
escape_char: Some('o'),
18611849
case_insensitive: true,
18621850
}),
1863-
r#"a ILIKE 'foo' ESCAPE 'o'"#,
1851+
r#"a LIKE 'foo' ESCAPE 'o'"#,
18641852
),
18651853
(
18661854
Expr::Literal(ScalarValue::Date64(Some(0))),

0 commit comments

Comments
 (0)