Skip to content

Conversation

@cgivre
Copy link
Contributor

@cgivre cgivre commented Oct 9, 2025

DRILL-3962: Add Support For ROLLUP, CUBE, GROUPING SETS, GROUPING, GROUPING_ID, GROUP_ID

Description

In recent versions of SQL, there are several aggregates which create different summaries of the aggregate data.

Specifically, this PR adds support for:

  • GROUPING SETS
  • ROLLUP
  • CUBE
  • GROUPING()
  • GROUPING_ID()
  • GROUP_ID()

Documentation

GROUPING SETS:

GROUPING SETS allows you to define multiple independent groupings within a single GROUP BY query. Instead of writing separate queries for each aggregation, you can specify different column combinations to produce multiple summary results at once. It gives you fine-grained control over which subtotals are calculated.

SELECT department_id, position_title, SUM(salary) AS total_salary
FROM cp.`employee.json`
GROUP BY GROUPING SETS ((department_id), (position_title), ())

ROLLUP

ROLLUP generates hierarchical aggregations that move from detailed data to higher-level summaries. For example, a ROLLUP on (year, month, day) produces totals by day, month, year, and an overall grand total. It’s ideal for creating reports with cumulative subtotals.

SELECT position_title, education_level, AVG(salary) AS avg_salary
FROM cp.`employee.json`
GROUP BY ROLLUP (position_title, education_level);

CUBE

CUBE creates aggregations for all possible combinations of the specified columns. It’s useful for multidimensional analysis, such as computing totals across every dimension and their intersections. This produces the most comprehensive summary of the data.

SELECT position_title, 
education_level, 
AVG(salary) AS avg_salary
FROM cp.`employee.json`
GROUP BY CUBE (position_title, education_level);

Testing

Created additional unit tests.

@cgivre cgivre self-assigned this Oct 9, 2025
@cgivre cgivre added enhancement PRs that add a new functionality to Drill doc-impacting PRs that affect the documentation labels Oct 9, 2025
@cgivre cgivre marked this pull request as draft October 9, 2025 18:03
@cgivre cgivre changed the title DRILL-3962: Add support of ROLLUP, CUBE, GROUPING SETS, GROUPING, GROUPING_ID, GROUP_ID support DRILL-3962: Add support of ROLLUP, CUBE, GROUPING SETS, GROUPING, GROUPING_ID, GROUP_ID Oct 9, 2025
@cgivre cgivre requested a review from jnturton October 10, 2025 20:45
@cgivre cgivre changed the title DRILL-3962: Add support of ROLLUP, CUBE, GROUPING SETS, GROUPING, GROUPING_ID, GROUP_ID DRILL-3962: Add Support For ROLLUP, CUBE, GROUPING SETS, GROUPING, GROUPING_ID, GROUP_ID Oct 10, 2025
@cgivre cgivre marked this pull request as ready for review October 12, 2025 04:47
Copy link
Member

@rymarm rymarm left a comment

Choose a reason for hiding this comment

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

Hi @cgivre, I think it would be a good idea to split code from a single method for hundreds of rows into separate helper methods to improve code readability and maintainability. Please check my comments.

The overall change looks good to me, thank you for this!

@cgivre
Copy link
Contributor Author

cgivre commented Oct 16, 2025

@rymarm Thanks for the review. I addressed all your comments.

@cgivre cgivre requested a review from rymarm October 20, 2025 15:12
Copy link
Member

@rymarm rymarm left a comment

Choose a reason for hiding this comment

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

@cgivre Thank you for all the changes! LGTM +1

@cgivre
Copy link
Contributor Author

cgivre commented Oct 24, 2025

Thanks @rymarm for the review!

@cgivre cgivre merged commit 261f526 into apache:master Oct 24, 2025
7 checks passed
@cgivre cgivre deleted the grouping_sets branch October 24, 2025 14:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

doc-impacting PRs that affect the documentation enhancement PRs that add a new functionality to Drill

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants