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

Fix all key value is null and group use rollup return wrong answer #49282

Merged
merged 1 commit into from May 5, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions src/Interpreters/Aggregator.cpp
Expand Up @@ -2102,6 +2102,7 @@ Aggregator::convertToBlockImplNotFinal(Method & method, Table & data, Arenas & a

std::optional<OutputBlockColumns> out_cols;
std::optional<Sizes> shuffled_key_sizes;
size_t rows_in_current_block = 0;

auto init_out_cols = [&]()
{
Expand All @@ -2116,6 +2117,7 @@ Aggregator::convertToBlockImplNotFinal(Method & method, Table & data, Arenas & a
for (size_t i = 0; i < params.aggregates_size; ++i)
out_cols->aggregate_columns_data[i]->push_back(data.getNullKeyData() + offsets_of_aggregate_states[i]);

++rows_in_current_block;
data.getNullKeyData() = nullptr;
data.hasNullKeyData() = false;
}
Expand All @@ -2127,8 +2129,6 @@ Aggregator::convertToBlockImplNotFinal(Method & method, Table & data, Arenas & a
// should be invoked at least once, because null data might be the only content of the `data`
init_out_cols();

size_t rows_in_current_block = 0;

data.forEachValue(
[&](const auto & key, auto & mapped)
{
Expand Down
@@ -0,0 +1,10 @@
\N 2

\N 2
\N 2

\N 2
\N 2
\N 2
\N 2
\N 2
13 changes: 13 additions & 0 deletions tests/queries/0_stateless/02725_null_group_key_with_rollup.sql
@@ -0,0 +1,13 @@
set allow_suspicious_low_cardinality_types=1;
DROP TABLE IF EXISTS group_by_null_key;
CREATE TABLE group_by_null_key (c1 Nullable(Int32), c2 LowCardinality(Nullable(Int32))) ENGINE = Memory();
INSERT INTO group_by_null_key VALUES (null, null), (null, null);

select c1, count(*) from group_by_null_key group by c1 WITH TOTALS;
select c2, count(*) from group_by_null_key group by c2 WITH TOTALS;

select c1, count(*) from group_by_null_key group by ROLLUP(c1);
select c2, count(*) from group_by_null_key group by ROLLUP(c2);


DROP TABLE group_by_null_key;