findepi commented on code in PR #13288:
URL: https://github.com/apache/datafusion/pull/13288#discussion_r1832349805
##########
datafusion/sqllogictest/test_files/string/string_literal.slt:
##########
@@ -15,6 +15,15 @@
# specific language governing permissions and limitations
# under the License.
+# a backslash in a string literal is not a special character
+query T
+VALUES ('\'), ('\\'), ('\\\'), ('\\\\')
+----
+\
+\\
+\\\
+\\\\
Review Comment:
This query (and all other queries involving a `\` backslash) would behave
differently in the CLI
https://github.com/apache/datafusion/issues/13286
##########
datafusion/sqllogictest/test_files/string/string_literal.slt:
##########
@@ -829,3 +838,95 @@ SELECT
'a' LIKE '%'
----
NULL true true
+
+# \ is an implicit escape character
Review Comment:
When working on https://github.com/apache/datafusion/pull/13260 i didn't
know that \ is an implicit escape character. I couldn't find any tests for
this, so here they come.
##########
datafusion/sqllogictest/test_files/string/string_literal.slt:
##########
@@ -829,3 +838,95 @@ SELECT
'a' LIKE '%'
----
NULL true true
+
+# \ is an implicit escape character
+query BBBB
+SELECT
+ 'a' LIKE '\%',
+ '\a' LIKE '\%',
+ '%' LIKE '\%',
+ '\%' LIKE '\%'
+----
+false false true false
+
+# \ is an implicit escape character
+query BBBBBB
+SELECT
+ 'a' LIKE '\_',
+ '\a' LIKE '\_',
+ '_' LIKE '\_',
+ '\_' LIKE '\_',
+ 'abc' LIKE 'a_c',
+ 'abc' LIKE 'a\_c'
+----
+false false true false true false
+
+# \ as an explicit escape character is currently not supported
+query error DataFusion error: SQL error: ParserError\("Expected end of
statement, found: \\\\"\)
+SELECT
+ 'a' LIKE '\%' ESCAPE '\',
+ '\a' LIKE '\%' ESCAPE '\',
+ '%' LIKE '\%' ESCAPE '\',
+ '\%' LIKE '\% ESCAPE '\''
+
+# \ as an explicit escape character is currently not supported
+query error DataFusion error: Execution error: LIKE does not support
escape_char
+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
+SELECT
+ '' LIKE '\',
+ '' LIKE '\\',
+ '' LIKE '\_',
+ '' LIKE '\%',
+ '' LIKE '\a'
+----
+false false false false false
+
+# escape before non-wildcard matches the escape itself
+query BBBBBBB
+SELECT
+ 'a' LIKE '\a',
+ '\a' LIKE '\a',
+ '\a' LIKE '\b',
+ '\' LIKE '\',
+ '\\' LIKE '\',
+ '\' LIKE '\\',
+ '\\' LIKE '\\'
+----
+false true false true false false true
+
+# if "%%" in the pattern was simplified to "%", the pattern semantics would
change
+query BBBBB
+SELECT
+ '%' LIKE '\%%',
+ '%%' LIKE '\%%',
+ '\%%' LIKE '\%%',
+ '%abc' LIKE '\%%',
+ '\%abc' LIKE '\%%'
+----
+true true false true false
+
+statement ok
+create table inputs AS SELECT * FROM (VALUES ('%'), ('%%'), ('\%%'), ('%abc'),
('\%abc')) t(a);
+
+# if "%%" in the pattern was simplified to "%", the pattern semantics would
change
+# same as above query, but with data coming from a table, so that constant
folding cannot kick in, but expression simplification can
+query TB
+SELECT a, a LIKE '\%%' FROM inputs
+----
+% true
+%% true
+\%% false
+%abc true
+\%abc false
Review Comment:
This would prevent a regression
https://github.com/apache/datafusion/pull/13260#discussion_r1832239184
##########
datafusion/sqllogictest/test_files/string/string_literal.slt:
##########
@@ -829,3 +838,95 @@ SELECT
'a' LIKE '%'
----
NULL true true
+
+# \ is an implicit escape character
+query BBBB
+SELECT
+ 'a' LIKE '\%',
+ '\a' LIKE '\%',
+ '%' LIKE '\%',
+ '\%' LIKE '\%'
+----
+false false true false
+
+# \ is an implicit escape character
+query BBBBBB
+SELECT
+ 'a' LIKE '\_',
+ '\a' LIKE '\_',
+ '_' LIKE '\_',
+ '\_' LIKE '\_',
+ 'abc' LIKE 'a_c',
+ 'abc' LIKE 'a\_c'
+----
+false false true false true false
+
+# \ as an explicit escape character is currently not supported
+query error DataFusion error: SQL error: ParserError\("Expected end of
statement, found: \\\\"\)
+SELECT
+ 'a' LIKE '\%' ESCAPE '\',
+ '\a' LIKE '\%' ESCAPE '\',
+ '%' LIKE '\%' ESCAPE '\',
+ '\%' LIKE '\% ESCAPE '\''
+
+# \ as an explicit escape character is currently not supported
+query error DataFusion error: Execution error: LIKE does not support
escape_char
+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
+SELECT
+ '' LIKE '\',
+ '' LIKE '\\',
+ '' LIKE '\_',
+ '' LIKE '\%',
+ '' LIKE '\a'
+----
+false false false false false
+
+# escape before non-wildcard matches the escape itself
+query BBBBBBB
+SELECT
+ 'a' LIKE '\a',
+ '\a' LIKE '\a',
+ '\a' LIKE '\b',
+ '\' LIKE '\',
+ '\\' LIKE '\',
+ '\' LIKE '\\',
+ '\\' LIKE '\\'
+----
+false true false true false false true
+
+# if "%%" in the pattern was simplified to "%", the pattern semantics would
change
+query BBBBB
+SELECT
+ '%' LIKE '\%%',
+ '%%' LIKE '\%%',
+ '\%%' LIKE '\%%',
+ '%abc' LIKE '\%%',
+ '\%abc' LIKE '\%%'
+----
+true true false true false
+
+statement ok
+create table inputs AS SELECT * FROM (VALUES ('%'), ('%%'), ('\%%'), ('%abc'),
('\%abc')) t(a);
Review Comment:
Testing below query with VALUES should be enough... unless/until we have
"push projection into values" optimization.
Maybe i should replace this with non-inlinable values using random?
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]