Skip to content
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

Add support for Hive dialect GROUPING SETS. #1539

Merged
merged 3 commits into from
Jul 6, 2022
Merged

Conversation

qzchenwl
Copy link
Contributor

Hive dialect requires all columns appear in GROUPING SETS clause to be in GROUP BY clause.

SELECT a, b, SUM( c ) FROM tab1 GROUP BY a, b GROUPING SETS ( (a, b), a, b, ( ) )

@@ -2734,6 +2734,19 @@ GroupByElement GroupByColumnReferences():
<K_GROUP> <K_BY>
( LOOKAHEAD(2) (
"(" ")" { groupBy.withUsingBrackets(true); }
(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you more compress this production? There are three nearly identical copies of this inserted block.

+ " Sometable\n"
+ "GROUP BY C1, C2, C3 GROUPING SETS ((C1, C2), (C1, C2, C3), ())";

statement = CCJSqlParserUtil.parse(sql);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This hole parsing process is done using assertSqlCanBeParsedAndDeparsed. So you could skip it.

@wumpz
Copy link
Member

wumpz commented May 19, 2022

I still do not get the difference to our current grouping sets variant. Could you explain more specific what you want to achieve?

@qzchenwl
Copy link
Contributor Author

JsqlParser could not parse SELECT a, b, SUM( c ) FROM tab1 GROUP BY a, b GROUPING SETS ( (a, b), a, b, ( ) ), it's a legal Hive statement.

It's an equivalent of Presto's SELECT a, b, SUM( c ) FROM tab1 GROUP BY GROUPING SETS ( (a, b), a, b, ( ) ).

@qzchenwl qzchenwl requested a review from wumpz May 23, 2022 06:18
@wumpz
Copy link
Member

wumpz commented Jun 8, 2022

Could you change the test method, like I requested?

@qzchenwl
Copy link
Contributor Author

Could you change the test method, like I requested?

The test method is changed now.

@wumpz wumpz merged commit 03c58de into JSQLParser:master Jul 6, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants