Skip to content

Implement Underlying Grouping Sets #42631

Closed

Description

@AilinKid

Feature Request

Is your feature request related to a problem? Please describe:

Grouping Sets is internal implementation mechanism for supporting Multi-Distinct-Aggregate MPP Optimization and Rollup/Cube syntax.

SELECT a, b, sum(expression) FROM table GROUP BY a, b With Rollup;

For modern databases like Spark SQL, it allows user to explicitly describe wanted grouping sets explicitly like this:

SELECT a, b, sum(expression) FROM table GROUP BY a, b GROUPING SETS((a,b),(x,x),(...));

Different listed grouping sets/grouping layout requirement above will ask the underlying data to be expanded as multi copies to feed different requirement of Aggregation granularity. As a consequence, the leveled-aggregated result rows will be a union to user.

Apart from explicit requirement from sql syntax level, there is a another way to implicitly describe a composed grouping sets. That's what exactly rollup and cube syntax does. For more detail about a example like rollup(a,b,c), it has implicit N = 4 grouping sets derived from incremental expression composition, such as grouping sets (), (a),(a,b),(a,b,c), so does cube syntax which will be more complicated one.

For Multi Distinct Aggregate case like

select count(distinct a), count(distinct b) from t

distinct nature require a implement of aggregation on groups grouped by a or b here, while single one copy of data can't satisfied both grouping by a and grouping b synchronously. As a consequence, we resort to different grouping sets like (a) and (b) to ask the underlying data to be expanded to feed different aggregation vertically.

Both of the 3 cases above is dependent/based on the implementation of Grouping Sets and Expand Operator, so that's why this issue calls for.

Describe the feature you'd like:

Shown above.

Describe alternatives you've considered:

For Rollup Syntax workaround, rewrite the SQL as union of many sub-query with individual group by items.
For Multi Distinct Aggregate Optimization workaround, there is no way to migrate the computation task to multi mpp nodes.

Teachability, Documentation, Adoption, Migration Strategy:

related issues schedule

Underlying Grouping Sets and Expand Operator

Rollup Syntax

Infra Support

Plan Operator

Bug Fix

Activity

  1. added 3 commits that reference this issue on Jul 24, 2024
    cbe807f
    0abf3ae
    5d5de41
  2. added 2 commits that reference this issue on Aug 1, 2024
    bd6e509
    f023067
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions