Skip to content

Support GROUPING SETS#33631

Merged
KochetovNicolai merged 61 commits intomasterfrom
grouping-sets-fix
May 11, 2022
Merged

Support GROUPING SETS#33631
KochetovNicolai merged 61 commits intomasterfrom
grouping-sets-fix

Conversation

@novikd
Copy link
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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
Copy Markdown
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 novikd requested a review from KochetovNicolai May 5, 2022 18:40
@novikd
Copy link
Copy Markdown
Member Author

novikd commented May 9, 2022

@Mergifyio update

@mergify
Copy link
Copy Markdown
Contributor

mergify bot commented May 9, 2022

update

✅ Branch has been successfully updated

@KochetovNicolai
Copy link
Copy Markdown
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

pr-feature Pull request with new product feature

Projects

None yet

Development

Successfully merging this pull request may close these issues.

9 participants