Skip to content

Remove LowCardinality from window function args.#31888

Merged
alexey-milovidov merged 9 commits intomasterfrom
fix-31114
Dec 12, 2021
Merged

Remove LowCardinality from window function args.#31888
alexey-milovidov merged 9 commits intomasterfrom
fix-31114

Conversation

@KochetovNicolai
Copy link
Copy Markdown
Member

@KochetovNicolai KochetovNicolai commented Nov 26, 2021

Changelog category (leave one):

  • Bug Fix (user-visible misbehaviour in official stable or prestable release):

Changelog Entry:
Fix possible crash (or incorrect result) in case of LowCardinality arguments of window function. Fixes #31114

@robot-clickhouse robot-clickhouse added the pr-bugfix Pull request with bugfix, not backported by default label Nov 26, 2021
auto columns = chunk.detachColumns();
for (auto & column : columns)
column = std::move(column)->convertToFullColumnIfConst();
column = recursiveRemoveLowCardinality(std::move(column)->convertToFullColumnIfConst());
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.

Could you please provide some insights?

Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov left a comment

Choose a reason for hiding this comment

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

.

@alexey-milovidov alexey-milovidov self-assigned this Nov 26, 2021
// Another problem with Const columns is that the aggregate functions
// can't work with them, so we have to materialize them like the
// Aggregator does.
// Likewise, aggregate functions can't work with LowCardinality,
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.

Then why we didn't get exception in their factory methods?

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 was looking into this the other day (for a crazy idea of handling const columns in the aggregation functions) and saw it here:

auto column_no_lc = recursiveRemoveLowCardinality(aggregate_columns[i][j]->getPtr());

Both const and low cardinality columns are converted to full. Not very efficient but it works.

Copy link
Copy Markdown
Member

@alexey-milovidov alexey-milovidov Nov 30, 2021

Choose a reason for hiding this comment

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

I know. But the difference is that const does not affect the data type and LowCardinality does.
So, why AggregateFunctionFactory accepted LowCardinality if aggregate functions don't support it?

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.

Aggregate function factory also converts all LC types to ordinary

AggregateFunctionPtr AggregateFunctionFactory::get(
const String & name, const DataTypes & argument_types, const Array & parameters, AggregateFunctionProperties & out_properties) const
{
auto type_without_low_cardinality = convertLowCardinalityTypesToNested(argument_types);

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, let's fix the checks and merge.

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.

Aggregate function factory also converts all LC types to ordinary

This is a tech debt after introducing LowCardinality.
Your code is doing one thing and expecting that some other unrelated code is doing the same thing.

It is very inconsistent.

It should work in the following way:
- if Aggregate Function Factory has created an aggregate function with some argument types, we should be able to pass the values of these types inside the aggregate function.

@alexey-milovidov alexey-milovidov merged commit 71df622 into master Dec 12, 2021
@alexey-milovidov alexey-milovidov deleted the fix-31114 branch December 12, 2021 03:37
KochetovNicolai added a commit that referenced this pull request Dec 13, 2021
Backport #31888 to 21.11: Remove LowCardinality from window function args.
KochetovNicolai added a commit that referenced this pull request Dec 13, 2021
Backport #31888 to 21.12: Remove LowCardinality from window function args.
KochetovNicolai added a commit that referenced this pull request Dec 13, 2021
…371fc4fd525c7a8a404425c17fcee

Cherry pick #31888 to 21.8: Remove LowCardinality from window function args.
KochetovNicolai added a commit that referenced this pull request Dec 13, 2021
…371fc4fd525c7a8a404425c17fcee

Cherry pick #31888 to 21.9: Remove LowCardinality from window function args.
KochetovNicolai added a commit that referenced this pull request Dec 13, 2021
…0371fc4fd525c7a8a404425c17fcee

Cherry pick #31888 to 21.10: Remove LowCardinality from window function args.
KochetovNicolai added a commit that referenced this pull request Dec 20, 2021
Backport #31888 to 21.10: Remove LowCardinality from window function args.
KochetovNicolai added a commit that referenced this pull request Dec 21, 2021
Backport #31888 to 21.8: Remove LowCardinality from window function args.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

pr-bugfix Pull request with bugfix, not backported by default

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Crash in window function with LowCardinality datatype

4 participants