[#35619]: Add support for GROUPING SETS, CUBE, and ROLLUP in HogQL #45877
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.
Problem
Users performing multi-axis analytics need flexible grouping options. Currently, HogQL parses but doesn't implement
CUBEandROLLUP, and doesn't supportGROUPING SETSat all. This makes it difficult to create queries that group data across multiple dimensions without extensive copy-pasting.Closes #35619
Changes
GROUPINGandSETStokens toHogQLLexer.common.g4groupByClauserule inHogQLParser.g4to properly capture CUBE, ROLLUP, and GROUPING SETS syntaxgroup_by_modifier(CUBE/ROLLUP) andgrouping_setsfields toSelectQueryinast.pyparser_python.cppandparser_json.cppto extract and populate the new AST fieldsTraversingVisitorandCloningVisitorinvisitor.pyto handle new fieldsresolver.pyto clone the new fields_build_group_by_clausemethod inprinter/base.pywith security limitsMAX_CUBE_ROLLUP_COLUMNS=10andMAX_GROUPING_SETS=64limits inconstants.pyto prevent resource exhaustionHow did you test this code?
_test_parser.pyfor CUBE, ROLLUP, and GROUPING SETS syntaxtest_printer.pyfor SQL output verificationQueryError)Publish to changelog?
Yes - This enables users to use
GROUP BY CUBE(),GROUP BY ROLLUP(), andGROUP BY GROUPING SETS()in HogQL queries for flexible multi-axis analytics.