Merge pull request #49282 from loneylee/49280

Fix all key value is null and group use rollup return wrong answer
This commit is contained in:
Alexey Milovidov 2023-05-05 06:43:41 +03:00 committed by GitHub
commit dfbba48510
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 25 additions and 2 deletions

View File

@ -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 = [&]()
{
@ -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;
}
@ -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)
{

View File

@ -0,0 +1,10 @@
\N 2
\N 2
\N 2
\N 2
\N 2
\N 2
\N 2
\N 2

View File

@ -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;