-
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-35026][SQL] Support nested CUBE/ROLLUP/GROUPING SETS in GROUPING SETS #32201
Changes from 1 commit
f18045a
3e68320
3e6cd44
52bbd99
b86873d
9783eeb
0b472e8
ede77ad
ace3d30
73478ca
866a373
cdbe1c7
3b97a8d
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -601,14 +601,24 @@ aggregationClause | |
; | ||
|
||
groupByClause | ||
: groupingAnalytics | ||
: nestedGroupingSets | ||
| groupingAnalytics | ||
| expression | ||
; | ||
|
||
nestedGroupingSets | ||
: GROUPING SETS '(' nestedGroupingSet (',' nestedGroupingSet)* ')' | ||
; | ||
|
||
groupingAnalytics | ||
: (ROLLUP | CUBE | GROUPING SETS) '(' groupingSet (',' groupingSet)* ')' | ||
; | ||
|
||
nestedGroupingSet | ||
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. How about 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. Done |
||
: groupingAnalytics | ||
| '(' (expression (',' expression)*)? ')' | ||
; | ||
|
||
groupingSet | ||
: '(' (expression (',' expression)*)? ')' | ||
| expression | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -80,3 +80,8 @@ SELECT a, b, count(1) FROM testData GROUP BY a, GROUPING SETS((a, b), (a), ()); | |
SELECT a, b, count(1) FROM testData GROUP BY a, CUBE(a, b), GROUPING SETS((a, b), (a), ()); | ||
SELECT a, b, count(1) FROM testData GROUP BY a, CUBE(a, b), ROLLUP(a, b), GROUPING SETS((a, b), (a), ()); | ||
|
||
-- Support use CUBE/ROLLUP/GROUPING SETS in GROUPING SETS | ||
AngersZhuuuu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
SELECT a, b, count(1) FROM testData GROUP BY a, GROUPING SETS(ROLLUP(a, b)); | ||
SELECT a, b, count(1) FROM testData GROUP BY a, GROUPING SETS((a, b), (a), ()); | ||
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. This test is related to this PR? 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.
Hmmm what to show
is equal to
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. But, this test is the same with one in L79? 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.
Remove this line |
||
SELECT a, b, count(1) FROM testData GROUP BY a, GROUPING SETS(GROUPING SETS((a, b), (a), ())); | ||
AngersZhuuuu marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
-- Automatically generated by SQLQueryTestSuite | ||
-- Number of queries: 44 | ||
-- Number of queries: 47 | ||
|
||
|
||
-- !query | ||
|
@@ -1067,3 +1067,60 @@ struct<a:int,b:int,count(1):bigint> | |
3 NULL 2 | ||
3 NULL 2 | ||
3 NULL 2 | ||
|
||
|
||
-- !query | ||
SELECT a, b, count(1) FROM testData GROUP BY a, GROUPING SETS(ROLLUP(a, b)) | ||
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: Just in case, I've checked all the results here are the same with PostgreSQL ones. 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. Thanks for your double check. |
||
-- !query schema | ||
struct<a:int,b:int,count(1):bigint> | ||
-- !query output | ||
1 1 1 | ||
1 2 1 | ||
1 NULL 2 | ||
1 NULL 2 | ||
2 1 1 | ||
2 2 1 | ||
2 NULL 2 | ||
2 NULL 2 | ||
3 1 1 | ||
3 2 1 | ||
3 NULL 2 | ||
3 NULL 2 | ||
|
||
|
||
-- !query | ||
SELECT a, b, count(1) FROM testData GROUP BY a, GROUPING SETS((a, b), (a), ()) | ||
-- !query schema | ||
struct<a:int,b:int,count(1):bigint> | ||
-- !query output | ||
1 1 1 | ||
1 2 1 | ||
1 NULL 2 | ||
1 NULL 2 | ||
2 1 1 | ||
2 2 1 | ||
2 NULL 2 | ||
2 NULL 2 | ||
3 1 1 | ||
3 2 1 | ||
3 NULL 2 | ||
3 NULL 2 | ||
|
||
|
||
-- !query | ||
SELECT a, b, count(1) FROM testData GROUP BY a, GROUPING SETS(GROUPING SETS((a, b), (a), ())) | ||
-- !query schema | ||
struct<a:int,b:int,count(1):bigint> | ||
-- !query output | ||
1 1 1 | ||
1 2 1 | ||
1 NULL 2 | ||
1 NULL 2 | ||
2 1 1 | ||
2 2 1 | ||
2 NULL 2 | ||
2 NULL 2 | ||
3 1 1 | ||
3 2 1 | ||
3 NULL 2 | ||
3 NULL 2 |
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.
What if we have (2 or more)-nested grouping sets?
GROUPING SETS(GROUPING SETS(GROUPING SETS(...
? I think we need tests for it.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.
Good catch..Just tested, PG support nested grouping sets.