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

Support GROUPING SETS #33631

Merged
merged 61 commits into from
May 11, 2022
Merged

Support GROUPING SETS #33631

merged 61 commits into from
May 11, 2022

Conversation

novikd
Copy link
Member

@novikd novikd commented Jan 14, 2022

Changelog category (leave one):

  • New Feature

Changelog entry (a user-readable short description of the changes that goes to CHANGELOG.md):

Add support of GROUPING SETS in GROUP BY clause. Follow up after #33186. This implementation supports a parallel processing of grouping sets.

Comment on lines +29 to +37
if (frame.surround_each_list_element_with_parens)
settings.ostr << "(";

FormatStateStacked frame_nested = frame;
frame_nested.surround_each_list_element_with_parens = false;
(*it)->formatImpl(settings, state, frame_nested);

if (frame.surround_each_list_element_with_parens)
settings.ostr << ")";
Copy link
Member

Choose a reason for hiding this comment

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

For some reason, I have an extra space while formatting in client:

ELECT
    SUM(number) AS sum_value,
    count() AS count_value
FROM numbers_mt(1000000)
GROUP BY
    GROUPING SETS (
    ( number % 10),
     ^ here
    ( number % 100))
     ^ here
ORDER BY
    sum_value ASC,
    count_value ASC

Copy link
Member Author

Choose a reason for hiding this comment

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

It's fixed in #32999

@KochetovNicolai
Copy link
Member

Compare result for

SELECT
    k1,
    k2,
    SUM(number) AS sum_value,
    count() AS count_value
FROM numbers(6)
GROUP BY
    GROUPING SETS (
    ( number % 2 AS k1),
    ( number % 3 AS k2))
ORDER BY
    sum_value ASC,
    count_value ASC

Query id: 080ee3d9-1856-41af-9185-775663655c71

┌─k1─┬─k2─┬─sum_value─┬─count_value─┐
│  0 │  0 │         3 │           2 │
│  0 │  1 │         5 │           2 │
│  0 │  0 │         6 │           3 │
│  0 │  2 │         7 │           2 │
│  1 │  0 │         9 │           3 │
└────┴────┴───────────┴─────────────┘

and

SELECT
    k1,
    k2,
    SUM(number) AS sum_value,
    count() AS count_value
FROM remote('127.0.0.{2,3}', numbers(6))
GROUP BY
    GROUPING SETS (
    ( number % 2 AS k1),
    ( number % 3 AS k2))
ORDER BY
    sum_value ASC,
    count_value ASC

Query id: 5fc9bf53-4389-4e9b-b4ab-4cee8ba5e082

┌─k1─┬─k2─┬─sum_value─┬─count_value─┐
│  0 │  1 │        10 │           4 │
│  0 │  2 │        14 │           4 │
│  1 │  0 │        18 │           6 │
│  0 │  0 │        18 │          10 │
└────┴────┴───────────┴─────────────┘

The key (0, 0) was squashed.
That's why we also need __grouping column for intermediate header (and merging transform should use in as an additional key)

Copy link
Member

@KochetovNicolai KochetovNicolai left a comment

Choose a reason for hiding this comment

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

Generally everything is ok.
Except it would be good to fix key squashing for the distributed case :)

@novikd
Copy link
Member Author

novikd commented May 9, 2022

@Mergifyio update

@mergify
Copy link
Contributor

mergify bot commented May 9, 2022

update

✅ Branch has been successfully updated

@KochetovNicolai
Copy link
Member

ok, failed tests does not seem to be relevant to the PR, merging.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
force tests The label does nothing, NOOP, None, nil pr-feature Pull request with new product feature
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

9 participants