-
Notifications
You must be signed in to change notification settings - Fork 28.2k
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
[SPARK-30724][SQL] Support 'LIKE ANY' and 'LIKE ALL' operators #27477
Closed
Closed
Changes from all commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
4548b0f
Support 'like any' and 'like all' operators
wangyum 5475675
operator -> quantifier
wangyum de7c398
address comments
wangyum caea82a
SOME -> ALL
wangyum 88ca4c2
Capitalize SQL keywords
wangyum 1c3d98c
Merge remote-tracking branch 'upstream/master' into SPARK-30724
wangyum 2b59cb0
Merge remote-tracking branch 'upstream/master' into SPARK-30724
wangyum 0656b05
Add a test case from our customers
wangyum cf4666f
Address comments
wangyum f9af131
Fix test error
wangyum File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
CREATE OR REPLACE TEMPORARY VIEW like_all_table AS SELECT * FROM (VALUES | ||
('google', '%oo%'), | ||
('facebook', '%oo%'), | ||
('linkedin', '%in')) | ||
as t1(company, pat); | ||
|
||
SELECT company FROM like_all_table WHERE company LIKE ALL ('%oo%', '%go%'); | ||
|
||
SELECT company FROM like_all_table WHERE company LIKE ALL ('microsoft', '%yoo%'); | ||
|
||
SELECT | ||
company, | ||
CASE | ||
WHEN company LIKE ALL ('%oo%', '%go%') THEN 'Y' | ||
ELSE 'N' | ||
END AS is_available, | ||
CASE | ||
WHEN company LIKE ALL ('%oo%', 'go%') OR company LIKE ALL ('%in', 'ms%') THEN 'Y' | ||
ELSE 'N' | ||
END AS mix | ||
FROM like_all_table ; | ||
|
||
-- Mix test with constant pattern and column value | ||
SELECT company FROM like_all_table WHERE company LIKE ALL ('%oo%', pat); | ||
|
||
-- not like all test | ||
SELECT company FROM like_all_table WHERE company NOT LIKE ALL ('%oo%', '%in', 'fa%'); | ||
SELECT company FROM like_all_table WHERE company NOT LIKE ALL ('microsoft', '%yoo%'); | ||
SELECT company FROM like_all_table WHERE company NOT LIKE ALL ('%oo%', 'fa%'); | ||
SELECT company FROM like_all_table WHERE NOT company LIKE ALL ('%oo%', 'fa%'); | ||
|
||
-- null test | ||
SELECT company FROM like_all_table WHERE company LIKE ALL ('%oo%', NULL); | ||
SELECT company FROM like_all_table WHERE company NOT LIKE ALL ('%oo%', NULL); | ||
SELECT company FROM like_all_table WHERE company LIKE ALL (NULL, NULL); | ||
SELECT company FROM like_all_table WHERE company NOT LIKE ALL (NULL, NULL); | ||
|
||
-- negative case | ||
SELECT company FROM like_any_table WHERE company LIKE ALL (); | ||
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
CREATE OR REPLACE TEMPORARY VIEW like_any_table AS SELECT * FROM (VALUES | ||
('google', '%oo%'), | ||
('facebook', '%oo%'), | ||
('linkedin', '%in')) | ||
as t1(company, pat); | ||
|
||
SELECT company FROM like_any_table WHERE company LIKE ANY ('%oo%', '%in', 'fa%'); | ||
|
||
SELECT company FROM like_any_table WHERE company LIKE ANY ('microsoft', '%yoo%'); | ||
|
||
select | ||
company, | ||
CASE | ||
WHEN company LIKE ANY ('%oo%', '%in', 'fa%') THEN 'Y' | ||
ELSE 'N' | ||
END AS is_available, | ||
CASE | ||
WHEN company LIKE ANY ('%oo%', 'fa%') OR company LIKE ANY ('%in', 'ms%') THEN 'Y' | ||
ELSE 'N' | ||
END AS mix | ||
FROM like_any_table; | ||
|
||
-- Mix test with constant pattern and column value | ||
SELECT company FROM like_any_table WHERE company LIKE ANY ('%zz%', pat); | ||
|
||
-- not like any test | ||
SELECT company FROM like_any_table WHERE company NOT LIKE ANY ('%oo%', '%in', 'fa%'); | ||
SELECT company FROM like_any_table WHERE company NOT LIKE ANY ('microsoft', '%yoo%'); | ||
SELECT company FROM like_any_table WHERE company NOT LIKE ANY ('%oo%', 'fa%'); | ||
SELECT company FROM like_any_table WHERE NOT company LIKE ANY ('%oo%', 'fa%'); | ||
|
||
-- null test | ||
SELECT company FROM like_any_table WHERE company LIKE ANY ('%oo%', NULL); | ||
SELECT company FROM like_any_table WHERE company NOT LIKE ANY ('%oo%', NULL); | ||
SELECT company FROM like_any_table WHERE company LIKE ANY (NULL, NULL); | ||
SELECT company FROM like_any_table WHERE company NOT LIKE ANY (NULL, NULL); | ||
|
||
-- negative case | ||
SELECT company FROM like_any_table WHERE company LIKE ANY (); |
140 changes: 140 additions & 0 deletions
140
sql/core/src/test/resources/sql-tests/results/like-all.sql.out
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,140 @@ | ||
-- Automatically generated by SQLQueryTestSuite | ||
-- Number of queries: 14 | ||
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. note: I've checked that the output is the same with PostgreSQL output: https://gist.github.com/maropu/fa4bd6491e21751d6bbc44c545390b0c |
||
-- !query | ||
CREATE OR REPLACE TEMPORARY VIEW like_all_table AS SELECT * FROM (VALUES | ||
('google', '%oo%'), | ||
('facebook', '%oo%'), | ||
('linkedin', '%in')) | ||
as t1(company, pat) | ||
-- !query schema | ||
struct<> | ||
-- !query output | ||
|
||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE company LIKE ALL ('%oo%', '%go%') | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE company LIKE ALL ('microsoft', '%yoo%') | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
|
||
-- !query | ||
SELECT | ||
company, | ||
CASE | ||
WHEN company LIKE ALL ('%oo%', '%go%') THEN 'Y' | ||
ELSE 'N' | ||
END AS is_available, | ||
CASE | ||
WHEN company LIKE ALL ('%oo%', 'go%') OR company LIKE ALL ('%in', 'ms%') THEN 'Y' | ||
ELSE 'N' | ||
END AS mix | ||
FROM like_all_table | ||
-- !query schema | ||
struct<company:string,is_available:string,mix:string> | ||
-- !query output | ||
facebook N N | ||
google Y Y | ||
linkedin N N | ||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE company LIKE ALL ('%oo%', pat) | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE company NOT LIKE ALL ('%oo%', '%in', 'fa%') | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE company NOT LIKE ALL ('microsoft', '%yoo%') | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE company NOT LIKE ALL ('%oo%', 'fa%') | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE NOT company LIKE ALL ('%oo%', 'fa%') | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE company LIKE ALL ('%oo%', NULL) | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE company NOT LIKE ALL ('%oo%', NULL) | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE company LIKE ALL (NULL, NULL) | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
|
||
-- !query | ||
SELECT company FROM like_all_table WHERE company NOT LIKE ALL (NULL, NULL) | ||
-- !query schema | ||
struct<company:string> | ||
-- !query output | ||
|
||
|
||
|
||
-- !query | ||
SELECT company FROM like_any_table WHERE company LIKE ALL () | ||
-- !query schema | ||
struct<> | ||
-- !query output | ||
org.apache.spark.sql.catalyst.parser.ParseException | ||
|
||
Expected something between '(' and ')'.(line 1, pos 49) | ||
|
||
== SQL == | ||
SELECT company FROM like_any_table WHERE company LIKE ALL () | ||
-------------------------------------------------^^^ |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is using of non-existing table intentional? I guess the purpose was to check
LIKE ALL ()
.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think it's a typo