Skip to content

Add GROUPING function#37163

Merged
KochetovNicolai merged 12 commits intomasterfrom
grouping-function
May 30, 2022
Merged

Add GROUPING function#37163
KochetovNicolai merged 12 commits intomasterfrom
grouping-function

Conversation

@novikd
Copy link
Copy Markdown
Member

@novikd novikd commented May 12, 2022

Changelog category (leave one):

  • New Feature

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

Add GROUPING function. Closes #19426

@robot-ch-test-poll2 robot-ch-test-poll2 added the pr-feature Pull request with new product feature label May 12, 2022
@novikd novikd marked this pull request as ready for review May 19, 2022 17:59
@KochetovNicolai KochetovNicolai self-assigned this May 25, 2022
class FunctionGroupingBase : public IFunction
{
protected:
static constexpr UInt64 ONE = 1;
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.

???

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.

I compute expressions like 1 << a several times and to avoid overflow I'd need to cast 1 literal to UInt64. It's simpler and more readable to introduce constexpr value.

return FunctionGroupingBase::executeImpl(arguments, input_rows_count,
[this](UInt64 set_index, UInt64 arg_index)
{
return arg_index < aggregation_keys_number - set_index;
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.

I've spend more than 5 min trying to understand what is happening in this row.
Can you add a comment?

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.

Also I hope this will be inlined ...

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.

I added comments for ROLLUP and CUBE, now it should be much easier to understand.
Here I use static polymorphism and compiler tends to inline this code. The same we have when use std::sort with comparator.

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.

Ok, now it's better - for ~5min I have managed to generally understand what's going on :)

Comment on lines +111 to +128
1 5
1 6
2 5
2 6
3 5
3 6
4 5
4 6
5 5
5 6
6 5
6 6
7 5
7 6
8 5
8 6
9 5
9 6
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.

Is it correct? I would not except that grouping(number, number % 2) would return 5 or 6

-- { echoOn }

may make tests more readable

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.

In this test we have grouping(number, number % 2) + 3

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 looks ok.
Could you add more comments?


ActionsVisitor::Data visitor_data(
context, SizeLimits{}, 1, {}, std::move(actions), prepared_sets, subqueries_for_sets, true, true, true, false);
context, SizeLimits{}, 1, source_columns, std::move(actions), prepared_sets, subqueries_for_sets, true, true, true, false,
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.

Here we for more than a year had a potential undefined behavior. ActionsVisitor::Data stores const reference to source_columns but temporary object was provided to the constructor.
I explicitly restricted passing of temporary objects to ActionsVisitor::Data constructor.

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.

GROUPING aggregate function

3 participants