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

Test LIKE with implicit \ escape #13288

Merged

Conversation

findepi
Copy link
Member

@findepi findepi commented Nov 7, 2024

More tests before #13260 lands.
Would prevent regression #13260 (comment)

@github-actions github-actions bot added the sqllogictest SQL Logic Tests (.slt) label Nov 7, 2024
Comment on lines +920 to +929
# 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
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This would prevent a regression #13260 (comment)

Comment on lines +20 to +25
VALUES ('\'), ('\\'), ('\\\'), ('\\\\')
----
\
\\
\\\
\\\\
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This query (and all other queries involving a \ backslash) would behave differently in the CLI
#13286

@@ -829,3 +838,95 @@ SELECT
'a' LIKE '%'
----
NULL true true

# \ is an implicit escape character
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When working on #13260 i didn't know that \ is an implicit escape character. I couldn't find any tests for this, so here they come.

true true false true false

statement ok
create table inputs AS SELECT * FROM (VALUES ('%'), ('%%'), ('\%%'), ('%abc'), ('\%abc')) t(a);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing below query with VALUES should be enough... unless/until we have "push projection into values" optimization.

I don't understand this -- there is only one column (t) and the query selects that column -- so there is no projection to push down 🤔

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it was for the case in which the inputs were not a table, but just VALUES ...

@findepi findepi force-pushed the findepi/test-like-with-implicit-escape-51b346 branch from f33b075 to 86abe17 Compare November 7, 2024 09:41
Comment on lines +26 to +27
('%', '\%', '', ''),
('_', '\_', '', ''),
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This feels duplicate with what i added in string_literal, but adds test coverage for all string variants

@findepi findepi force-pushed the findepi/test-like-with-implicit-escape-51b346 branch 2 times, most recently from d7de2e4 to 6c7d6ae Compare November 7, 2024 09:54
@findepi findepi force-pushed the findepi/test-like-with-implicit-escape-51b346 branch from 6c7d6ae to aea67f1 Compare November 7, 2024 11:06
Copy link
Contributor

@goldmedal goldmedal left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @findepi, it looks good to me 👍 . I think we can merge it before #13260
@alamb might want to take a look. Let's wait for him.

@findepi findepi force-pushed the findepi/test-like-with-implicit-escape-51b346 branch from aea67f1 to 6dd5744 Compare November 7, 2024 16:10
\a \\a false
\a % true
\a \% false
\a \\% false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks like a bug.
Given \ is an escape character, \\ should match single backslash character \ of the input,
and % should match the rest (a). The result should be true then

\\\\ \\a false
\\\\ % true
\\\\ \% false
\\\\ \\% false
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This one looks like a bug.
Given \ is an escape character, \\ should match single backslash character \ of the input,
and % should match the rest (\\\). The result should be true then

@findepi
Copy link
Member Author

findepi commented Nov 7, 2024

@goldmedal added a few more test cases.
It seems we have a bug somewhere in the LIKE's execution.

Marked examples #13288 (comment) #13288 (comment)

@findepi findepi force-pushed the findepi/test-like-with-implicit-escape-51b346 branch from 6dd5744 to bc54c50 Compare November 7, 2024 16:21
Copy link
Contributor

@alamb alamb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you @findepi and @goldmedal -- I think this does a great job documenting what our current LIKE behavior is. 🚀

true true false true false

statement ok
create table inputs AS SELECT * FROM (VALUES ('%'), ('%%'), ('\%%'), ('%abc'), ('\%abc')) t(a);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Testing below query with VALUES should be enough... unless/until we have "push projection into values" optimization.

I don't understand this -- there is only one column (t) and the query selects that column -- so there is no projection to push down 🤔

@alamb alamb merged commit 316e64a into apache:main Nov 7, 2024
25 checks passed
@findepi findepi deleted the findepi/test-like-with-implicit-escape-51b346 branch November 8, 2024 08:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
sqllogictest SQL Logic Tests (.slt)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants