-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-20334][SQL] Return a better error message when correlated predicates contain aggregate expression that has mixture of outer and local references. #17636
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
Closed
Closed
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
a266c8d
[SPARK-20334] Return a better error message when correlated predicate…
dilipbiswal bb1bdad
Code review
dilipbiswal ff88651
Code review
dilipbiswal c4e1a01
comments
dilipbiswal af3d367
review comments
dilipbiswal 55c64ca
review comments
dilipbiswal d986ddc
Simplify test
dilipbiswal 2411f3e
review comments
dilipbiswal 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 hidden or 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
74 changes: 52 additions & 22 deletions
74
sql/core/src/test/resources/sql-tests/inputs/subquery/negative-cases/invalid-correlation.sql
This file contains hidden or 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 |
|---|---|---|
| @@ -1,42 +1,72 @@ | ||
| -- The test file contains negative test cases | ||
| -- of invalid queries where error messages are expected. | ||
|
|
||
| create temporary view t1 as select * from values | ||
|
Member
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. Those just change for case, right?
Contributor
Author
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. @viirya Yeah.. since i was on this test case, thought i should fix the case. |
||
| CREATE TEMPORARY VIEW t1 AS SELECT * FROM VALUES | ||
| (1, 2, 3) | ||
| as t1(t1a, t1b, t1c); | ||
| AS t1(t1a, t1b, t1c); | ||
|
|
||
| create temporary view t2 as select * from values | ||
| CREATE TEMPORARY VIEW t2 AS SELECT * FROM VALUES | ||
| (1, 0, 1) | ||
| as t2(t2a, t2b, t2c); | ||
| AS t2(t2a, t2b, t2c); | ||
|
|
||
| create temporary view t3 as select * from values | ||
| CREATE TEMPORARY VIEW t3 AS SELECT * FROM VALUES | ||
| (3, 1, 2) | ||
| as t3(t3a, t3b, t3c); | ||
| AS t3(t3a, t3b, t3c); | ||
|
|
||
| -- TC 01.01 | ||
| -- The column t2b in the SELECT of the subquery is invalid | ||
| -- because it is neither an aggregate function nor a GROUP BY column. | ||
| select t1a, t2b | ||
| from t1, t2 | ||
| where t1b = t2c | ||
| and t2b = (select max(avg) | ||
| from (select t2b, avg(t2b) avg | ||
| from t2 | ||
| where t2a = t1.t1b | ||
| SELECT t1a, t2b | ||
| FROM t1, t2 | ||
| WHERE t1b = t2c | ||
| AND t2b = (SELECT max(avg) | ||
| FROM (SELECT t2b, avg(t2b) avg | ||
| FROM t2 | ||
| WHERE t2a = t1.t1b | ||
| ) | ||
| ) | ||
| ; | ||
|
|
||
| -- TC 01.02 | ||
| -- Invalid due to the column t2b not part of the output from table t2. | ||
| select * | ||
| from t1 | ||
| where t1a in (select min(t2a) | ||
| from t2 | ||
| group by t2c | ||
| having t2c in (select max(t3c) | ||
| from t3 | ||
| group by t3b | ||
| having t3b > t2b )) | ||
| SELECT * | ||
| FROM t1 | ||
| WHERE t1a IN (SELECT min(t2a) | ||
| FROM t2 | ||
| GROUP BY t2c | ||
| HAVING t2c IN (SELECT max(t3c) | ||
| FROM t3 | ||
| GROUP BY t3b | ||
| HAVING t3b > t2b )) | ||
| ; | ||
|
|
||
| -- TC 01.03 | ||
| -- Invalid due to mixure of outer and local references under an AggegatedExpression | ||
| -- in a correlated predicate | ||
| SELECT t1a | ||
| FROM t1 | ||
| GROUP BY 1 | ||
| HAVING EXISTS (SELECT 1 | ||
| FROM t2 | ||
| WHERE t2a < min(t1a + t2a)); | ||
|
|
||
| -- TC 01.04 | ||
| -- Invalid due to mixure of outer and local references under an AggegatedExpression | ||
| SELECT t1a | ||
| FROM t1 | ||
| WHERE t1a IN (SELECT t2a | ||
| FROM t2 | ||
| WHERE EXISTS (SELECT 1 | ||
| FROM t3 | ||
| GROUP BY 1 | ||
| HAVING min(t2a + t3a) > 1)); | ||
|
|
||
| -- TC 01.05 | ||
| -- Invalid due to outer reference appearing in projection list | ||
| SELECT t1a | ||
| FROM t1 | ||
| WHERE t1a IN (SELECT t2a | ||
| FROM t2 | ||
| WHERE EXISTS (SELECT min(t2a) | ||
| FROM t3)); | ||
|
|
||
This file contains hidden or 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 hidden or 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
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.
Do we have any test case to cover this scenario?
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.
@gatorsmile I couldn't find a test for this. I will add one for now in SubquerySuite. I will move the negative tests to the sqlquerytestsuite in a follow-up pr.