Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support LIKE with ESCAPE \ #13312

Merged
merged 2 commits into from
Nov 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions datafusion/physical-expr/src/planner.rs
Original file line number Diff line number Diff line change
Expand Up @@ -200,8 +200,11 @@ pub fn create_physical_expr(
escape_char,
case_insensitive,
}) => {
if escape_char.is_some() {
return exec_err!("LIKE does not support escape_char");
// `\` is the implicit escape, see https://github.com/apache/datafusion/issues/13291
if escape_char.unwrap_or('\\') != '\\' {
return exec_err!(
"LIKE does not support escape_char other than the backslash (\\)"
);
}
let physical_expr =
create_physical_expr(expr, input_dfschema, execution_props)?;
Expand Down
28 changes: 24 additions & 4 deletions datafusion/sqllogictest/test_files/string/string_literal.slt
Original file line number Diff line number Diff line change
Expand Up @@ -861,23 +861,43 @@ SELECT
----
false false true false true false

# \ as an explicit escape character is currently not supported
query error DataFusion error: Execution error: LIKE does not support escape_char
query BBBB
SELECT
'a' LIKE '\%' ESCAPE '\',
'\a' LIKE '\%' ESCAPE '\',
'%' LIKE '\%' ESCAPE '\',
'\%' LIKE '\%' ESCAPE '\'
----
false false true false

# \ as an explicit escape character is currently not supported
query error DataFusion error: Execution error: LIKE does not support escape_char
query BBBBBB
SELECT
'a' LIKE '\_' ESCAPE '\',
'\a' LIKE '\_' ESCAPE '\',
'_' LIKE '\_' ESCAPE '\',
'\_' LIKE '\_' ESCAPE '\',
'abc' LIKE 'a_c' ESCAPE '\',
'abc' LIKE 'a\_c' ESCAPE '\'
----
false false true false true false

# Only \ is currently supported as an explicit escape character
query error DataFusion error: Execution error: LIKE does not support escape_char other than the backslash \(\\\)
SELECT
'a' LIKE '$%' ESCAPE '$',
'\a' LIKE '$%' ESCAPE '$',
'%' LIKE '$%' ESCAPE '$',
'\%' LIKE '$%' ESCAPE '$'

# Only \ is currently supported as an explicit escape character
query error DataFusion error: Execution error: LIKE does not support escape_char other than the backslash \(\\\)
SELECT
'a' LIKE '$_' ESCAPE '$',
'\a' LIKE '$_' ESCAPE '$',
'_' LIKE '$_' ESCAPE '$',
'\_' LIKE '$_' ESCAPE '$',
'abc' LIKE 'a_c' ESCAPE '$',
'abc' LIKE 'a$_c' ESCAPE '$'

# a LIKE pattern containing escape can never match an empty string
query BBBBB
Expand Down