-
Notifications
You must be signed in to change notification settings - Fork 28.9k
[SPARK-24424][SQL] Support ANSI-SQL compliant syntax for GROUPING SET #21813
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
Changes from all commits
b5ada3f
ac8f04f
7cf187d
e0c57f7
2ecf3e1
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 |
|---|---|---|
|
|
@@ -13,5 +13,41 @@ SELECT a, b, c, count(d) FROM grouping GROUP BY a, b, c GROUPING SETS ((a)); | |
| -- SPARK-17849: grouping set throws NPE #3 | ||
| SELECT a, b, c, count(d) FROM grouping GROUP BY a, b, c GROUPING SETS ((c)); | ||
|
|
||
| -- Group sets without explicit group by | ||
| SELECT c1, sum(c2) FROM (VALUES ('x', 10, 0), ('y', 20, 0)) AS t (c1, c2, c3) GROUP BY GROUPING SETS (c1); | ||
|
|
||
| -- Group sets without group by and with grouping | ||
| SELECT c1, sum(c2), grouping(c1) FROM (VALUES ('x', 10, 0), ('y', 20, 0)) AS t (c1, c2, c3) GROUP BY GROUPING SETS (c1); | ||
|
|
||
| -- Mutiple grouping within a grouping set | ||
| SELECT c1, c2, Sum(c3), grouping__id | ||
| FROM (VALUES ('x', 'a', 10), ('y', 'b', 20) ) AS t (c1, c2, c3) | ||
| GROUP BY GROUPING SETS ( ( c1 ), ( c2 ) ) | ||
| HAVING GROUPING__ID > 1; | ||
|
|
||
| -- Group sets without explicit group by | ||
| SELECT grouping(c1) FROM (VALUES ('x', 'a', 10), ('y', 'b', 20)) AS t (c1, c2, c3) GROUP BY GROUPING SETS (c1,c2); | ||
|
|
||
| -- Mutiple grouping within a grouping set | ||
| SELECT -c1 AS c1 FROM (values (1,2), (3,2)) t(c1, c2) GROUP BY GROUPING SETS ((c1), (c1, c2)); | ||
|
|
||
| -- complex expression in grouping sets | ||
| SELECT a + b, b, sum(c) FROM (VALUES (1,1,1),(2,2,2)) AS t(a,b,c) GROUP BY GROUPING SETS ( (a + b), (b)); | ||
|
|
||
| -- complex expression in grouping sets | ||
| SELECT a + b, b, sum(c) FROM (VALUES (1,1,1),(2,2,2)) AS t(a,b,c) GROUP BY GROUPING SETS ( (a + b), (b + a), (b)); | ||
|
|
||
| -- more query constructs with grouping sets | ||
| SELECT c1 AS col1, c2 AS col2 | ||
| FROM (VALUES (1, 2), (3, 2)) t(c1, c2) | ||
| GROUP BY GROUPING SETS ( ( c1 ), ( c1, c2 ) ) | ||
| HAVING col2 IS NOT NULL | ||
| ORDER BY -col1; | ||
|
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. I've manually verified the results should be correct.
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 Sorry Simon.. do i have to do something for this comment ?
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. Not at all. @dilipbiswal :-) |
||
|
|
||
| -- negative tests - must have at least one grouping expression | ||
| SELECT a, b, c, count(d) FROM grouping GROUP BY WITH ROLLUP; | ||
|
|
||
| SELECT a, b, c, count(d) FROM grouping GROUP BY WITH CUBE; | ||
|
|
||
| SELECT c1 FROM (values (1,2), (3,2)) t(c1, c2) GROUP BY GROUPING SETS (()); | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.
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
GROUP BY GROUPING SETS (())? Is it a valid query?Uh oh!
There was an error while loading. Please reload this page.
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.
@viirya No. We should be getting an error as we don't have a group by specification. I had tried this scenario against db2 to double check.
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.
Can we have a test case for it too?
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.
@viirya Yeah.. was already adding it .. knew u would ask :-)
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.
@dilipbiswal Thanks! :-)