mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-11-22 07:31:57 +00:00
Merge pull request #40997 from canhld94/ch_canh_fix_grouping_set
Fix grouping set with group_by_use_nulls
This commit is contained in:
commit
981e9dbce2
@ -251,14 +251,17 @@ void AggregatingStep::transformPipeline(QueryPipelineBuilder & pipeline, const B
|
||||
outputs.push_back(grouping_node);
|
||||
|
||||
const auto & missing_columns = grouping_sets_params[set_counter].missing_keys;
|
||||
const auto & used_keys = grouping_sets_params[set_counter].used_keys;
|
||||
|
||||
auto to_nullable_function = FunctionFactory::instance().get("toNullable", nullptr);
|
||||
for (size_t i = 0; i < output_header.columns(); ++i)
|
||||
{
|
||||
auto & col = output_header.getByPosition(i);
|
||||
const auto it = std::find_if(
|
||||
const auto missing_it = std::find_if(
|
||||
missing_columns.begin(), missing_columns.end(), [&](const auto & missing_col) { return missing_col == col.name; });
|
||||
if (it != missing_columns.end())
|
||||
const auto used_it = std::find_if(
|
||||
used_keys.begin(), used_keys.end(), [&](const auto & used_col) { return used_col == col.name; });
|
||||
if (missing_it != missing_columns.end())
|
||||
{
|
||||
auto column_with_default = col.column->cloneEmpty();
|
||||
col.type->insertDefaultInto(*column_with_default);
|
||||
@ -270,7 +273,7 @@ void AggregatingStep::transformPipeline(QueryPipelineBuilder & pipeline, const B
|
||||
else
|
||||
{
|
||||
const auto * column_node = dag->getOutputs()[header.getPositionByName(col.name)];
|
||||
if (group_by_use_nulls && column_node->result_type->canBeInsideNullable())
|
||||
if (used_it != used_keys.end() && group_by_use_nulls && column_node->result_type->canBeInsideNullable())
|
||||
outputs.push_back(&dag->addFunction(to_nullable_function, { column_node }, col.name));
|
||||
else
|
||||
outputs.push_back(column_node);
|
||||
|
@ -213,3 +213,27 @@ SETTINGS group_by_use_nulls=1;
|
||||
\N \N 45
|
||||
|
||||
0 0 45
|
||||
SELECT
|
||||
number,
|
||||
number % 2,
|
||||
sum(number) AS val
|
||||
FROM numbers(10)
|
||||
GROUP BY
|
||||
GROUPING SETS (
|
||||
(number),
|
||||
(number % 2)
|
||||
)
|
||||
ORDER BY 1, tuple(val)
|
||||
SETTINGS group_by_use_nulls = 1, max_bytes_before_external_sort=10;
|
||||
0 \N 0
|
||||
1 \N 1
|
||||
2 \N 2
|
||||
3 \N 3
|
||||
4 \N 4
|
||||
5 \N 5
|
||||
6 \N 6
|
||||
7 \N 7
|
||||
8 \N 8
|
||||
9 \N 9
|
||||
\N 0 20
|
||||
\N 1 25
|
||||
|
@ -60,3 +60,16 @@ FROM numbers(10)
|
||||
GROUP BY CUBE(number, number % 2) WITH TOTALS
|
||||
ORDER BY (number, number % 2, val)
|
||||
SETTINGS group_by_use_nulls=1;
|
||||
|
||||
SELECT
|
||||
number,
|
||||
number % 2,
|
||||
sum(number) AS val
|
||||
FROM numbers(10)
|
||||
GROUP BY
|
||||
GROUPING SETS (
|
||||
(number),
|
||||
(number % 2)
|
||||
)
|
||||
ORDER BY 1, tuple(val)
|
||||
SETTINGS group_by_use_nulls = 1, max_bytes_before_external_sort=10;
|
||||
|
Loading…
Reference in New Issue
Block a user