From 6a644b2af10699be5a5f14b8cfb80ef1bc88c31f Mon Sep 17 00:00:00 2001 From: Amos Bird Date: Fri, 1 Jan 2021 12:42:22 +0800 Subject: [PATCH] Fix SimpleAggregateFunction in SummingMergeTree 2 --- .../Merges/Algorithms/SummingSortedAlgorithm.cpp | 4 ++-- ...regate_function_in_summing_merge_tree.reference | 1 + ...le_aggregate_function_in_summing_merge_tree.sql | 14 ++++++++++++++ 3 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Processors/Merges/Algorithms/SummingSortedAlgorithm.cpp b/src/Processors/Merges/Algorithms/SummingSortedAlgorithm.cpp index 61065aad5c3..749b460a934 100644 --- a/src/Processors/Merges/Algorithms/SummingSortedAlgorithm.cpp +++ b/src/Processors/Merges/Algorithms/SummingSortedAlgorithm.cpp @@ -215,8 +215,9 @@ static SummingSortedAlgorithm::ColumnsDefinition defineColumns( { const ColumnWithTypeAndName & column = header.safeGetByPosition(i); + const auto * simple = dynamic_cast(column.type->getCustomName()); /// Discover nested Maps and find columns for summation - if (typeid_cast(column.type.get())) + if (typeid_cast(column.type.get()) && !simple) { const auto map_name = Nested::extractTableName(column.name); /// if nested table name ends with `Map` it is a possible candidate for special handling @@ -231,7 +232,6 @@ static SummingSortedAlgorithm::ColumnsDefinition defineColumns( else { bool is_agg_func = WhichDataType(column.type).isAggregateFunction(); - const auto * simple = dynamic_cast(column.type->getCustomName()); /// There are special const columns for example after prewhere sections. if ((!column.type->isSummable() && !is_agg_func && !simple) || isColumnConst(*column.column)) diff --git a/tests/queries/0_stateless/01630_simple_aggregate_function_in_summing_merge_tree.reference b/tests/queries/0_stateless/01630_simple_aggregate_function_in_summing_merge_tree.reference index dbc5d8aae43..14f997de123 100644 --- a/tests/queries/0_stateless/01630_simple_aggregate_function_in_summing_merge_tree.reference +++ b/tests/queries/0_stateless/01630_simple_aggregate_function_in_summing_merge_tree.reference @@ -1 +1,2 @@ ([25],[1]) ([25],[1]) +[0,1] [0,1] diff --git a/tests/queries/0_stateless/01630_simple_aggregate_function_in_summing_merge_tree.sql b/tests/queries/0_stateless/01630_simple_aggregate_function_in_summing_merge_tree.sql index 764cebbc9a9..498c5d93a89 100644 --- a/tests/queries/0_stateless/01630_simple_aggregate_function_in_summing_merge_tree.sql +++ b/tests/queries/0_stateless/01630_simple_aggregate_function_in_summing_merge_tree.sql @@ -7,3 +7,17 @@ insert into test_smt select id, sumMap(k), sumMapState(k) from (select 2 as id, select sumMap(sMap), sumMapMerge(aMap) from test_smt; drop table if exists test_smt; + +drop table if exists simple_agf_summing_mt; + +create table simple_agf_summing_mt (a Int64, grp_aggreg AggregateFunction(groupUniqArrayArray, Array(UInt64)), grp_simple SimpleAggregateFunction(groupUniqArrayArray, Array(UInt64))) engine = SummingMergeTree() order by a; + +insert into simple_agf_summing_mt select 1 a, groupUniqArrayArrayState([toUInt64(number)]), groupUniqArrayArray([toUInt64(number)]) from numbers(1) group by a; + +insert into simple_agf_summing_mt select 1 a, groupUniqArrayArrayState([toUInt64(number)]), groupUniqArrayArray([toUInt64(number)]) from numbers(2) group by a; + +optimize table simple_agf_summing_mt final; + +SELECT arraySort(groupUniqArrayArrayMerge(grp_aggreg)) gra , arraySort(groupUniqArrayArray(grp_simple)) grs FROM simple_agf_summing_mt group by a; + +drop table if exists simple_agf_summing_mt;