-
Notifications
You must be signed in to change notification settings - Fork 28.6k
[SPARK-18863][SQL] Output non-aggregate expressions without GROUP BY in a subquery does not yield an error #16572
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
26 commits
Select commit
Hold shift + click to select a range
b988651
[SPARK-16804][SQL] Correlated subqueries containing LIMIT return inco…
nsyca 069ed8f
[SPARK-16804][SQL] Correlated subqueries containing LIMIT return inco…
nsyca edca333
New positive test cases
nsyca 64184fd
Fix unit test case failure
nsyca 29f82b0
blocking TABLESAMPLE
nsyca ac43ab4
Fixing code styling
nsyca 631d396
Correcting Scala test style
nsyca 7eb9b2d
One (last) attempt to correct the Scala style tests
nsyca 1387cf5
Merge remote-tracking branch 'upstream/master'
nsyca 3faa2d5
Merge remote-tracking branch 'upstream/master'
nsyca a308634
Merge remote-tracking branch 'upstream/master'
nsyca 2f463de
first fix (incomplete)
nsyca 6e2f686
first attempt
nsyca f1524b9
Merge remote-tracking branch 'upstream/master'
nsyca 6dfa8e5
Merge branch 'master' into 18863
nsyca e9bdde6
New test cases
nsyca deec874
Masking exprIDs
nsyca 5c36dce
Merge remote-tracking branch 'upstream/master'
nsyca 98cbd60
Merge branch 'master' into 18863
nsyca bcae336
reverse back accidental change
nsyca 51f7fb9
port from SPARK-19017
nsyca 24397cf
remove unrelated comment
nsyca ced19c7
address comment #1
nsyca 862b2b8
Merge remote-tracking branch 'upstream/master'
nsyca 203ad7d
Merge branch 'master' into 18863
nsyca 010d27a
remove blank line
nsyca 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
42 changes: 42 additions & 0 deletions
42
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 |
---|---|---|
@@ -0,0 +1,42 @@ | ||
-- The test file contains negative test cases | ||
-- of invalid queries where error messages are expected. | ||
|
||
create temporary view t1 as select * from values | ||
(1, 2, 3) | ||
as t1(t1a, t1b, t1c); | ||
|
||
create temporary view t2 as select * from values | ||
(1, 0, 1) | ||
as t2(t2a, t2b, t2c); | ||
|
||
create temporary view t3 as select * from values | ||
(3, 1, 2) | ||
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 | ||
) | ||
) | ||
; | ||
|
||
-- 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 )) | ||
; | ||
|
66 changes: 66 additions & 0 deletions
66
.../src/test/resources/sql-tests/results/subquery/negative-cases/invalid-correlation.sql.out
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 |
---|---|---|
@@ -0,0 +1,66 @@ | ||
-- Automatically generated by SQLQueryTestSuite | ||
-- Number of queries: 5 | ||
|
||
|
||
-- !query 0 | ||
create temporary view t1 as select * from values | ||
(1, 2, 3) | ||
as t1(t1a, t1b, t1c) | ||
-- !query 0 schema | ||
struct<> | ||
-- !query 0 output | ||
|
||
|
||
|
||
-- !query 1 | ||
create temporary view t2 as select * from values | ||
(1, 0, 1) | ||
as t2(t2a, t2b, t2c) | ||
-- !query 1 schema | ||
struct<> | ||
-- !query 1 output | ||
|
||
|
||
|
||
-- !query 2 | ||
create temporary view t3 as select * from values | ||
(3, 1, 2) | ||
as t3(t3a, t3b, t3c) | ||
-- !query 2 schema | ||
struct<> | ||
-- !query 2 output | ||
|
||
|
||
|
||
-- !query 3 | ||
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 | ||
) | ||
) | ||
-- !query 3 schema | ||
struct<> | ||
-- !query 3 output | ||
org.apache.spark.sql.AnalysisException | ||
expression 't2.`t2b`' is neither present in the group by, nor is it an aggregate function. Add to group by or wrap in first() (or first_value) if you don't care which value you get.; | ||
|
||
|
||
-- !query 4 | ||
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 )) | ||
-- !query 4 schema | ||
struct<> | ||
-- !query 4 output | ||
org.apache.spark.sql.AnalysisException | ||
resolved attribute(s) t2b#x missing from min(t2a)#x,t2c#x in operator !Filter predicate-subquery#x [(t2c#x = max(t3c)#x) && (t3b#x > t2b#x)]; |
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.
The best way to view this block of code changes is using a
diff
with-b
. The main part is to callcheckAnalysis
for both PredicateSubquery and ScalaSubquery.