Fix SimpleAggregateFunction in SummingMergeTree 2

This commit is contained in:
Amos Bird 2021-01-01 12:42:22 +08:00
parent 4165a58ce4
commit 6a644b2af1
No known key found for this signature in database
GPG Key ID: 80D430DCBECFEDB4
3 changed files with 17 additions and 2 deletions

View File

@ -215,8 +215,9 @@ static SummingSortedAlgorithm::ColumnsDefinition defineColumns(
{
const ColumnWithTypeAndName & column = header.safeGetByPosition(i);
const auto * simple = dynamic_cast<const DataTypeCustomSimpleAggregateFunction *>(column.type->getCustomName());
/// Discover nested Maps and find columns for summation
if (typeid_cast<const DataTypeArray *>(column.type.get()))
if (typeid_cast<const DataTypeArray *>(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<const DataTypeCustomSimpleAggregateFunction *>(column.type->getCustomName());
/// There are special const columns for example after prewhere sections.
if ((!column.type->isSummable() && !is_agg_func && !simple) || isColumnConst(*column.column))

View File

@ -1 +1,2 @@
([25],[1]) ([25],[1])
[0,1] [0,1]

View File

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