Merge pull request #18404 from amosbird/fixsimplestate

-SimpleState function arg type = return type
This commit is contained in:
alexey-milovidov 2020-12-24 12:12:29 +03:00 committed by GitHub
commit 4561527d4d
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 28 additions and 1 deletions

View File

@ -1,5 +1,6 @@
#pragma once
#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <AggregateFunctions/IAggregateFunction.h>
#include <DataTypes/DataTypeCustomSimpleAggregateFunction.h>
#include <DataTypes/DataTypeFactory.h>
@ -32,10 +33,17 @@ public:
DataTypePtr getReturnType() const override
{
DataTypeCustomSimpleAggregateFunction::checkSupportedFunctions(nested_func);
// Need to make a clone because it'll be customized.
auto storage_type = DataTypeFactory::instance().get(nested_func->getReturnType()->getName());
// Need to make a new function with promoted argument types because SimpleAggregates requires arg_type = return_type.
AggregateFunctionProperties properties;
auto function
= AggregateFunctionFactory::instance().get(nested_func->getName(), {storage_type}, nested_func->getParameters(), properties);
DataTypeCustomNamePtr custom_name
= std::make_unique<DataTypeCustomSimpleAggregateFunction>(nested_func, DataTypes{nested_func->getReturnType()}, params);
= std::make_unique<DataTypeCustomSimpleAggregateFunction>(function, DataTypes{nested_func->getReturnType()}, params);
storage_type->setCustomization(std::make_unique<DataTypeCustomDesc>(std::move(custom_name), nullptr));
return storage_type;
}

View File

@ -0,0 +1,6 @@
1 10
20 30
40 110
1 10
20 60
40 120

View File

@ -0,0 +1,13 @@
drop table if exists ay;
create table ay engine AggregatingMergeTree order by i as select 1 i, sumSimpleState(10) group by i;
insert into ay values(40, 60);
insert into ay values(40, 50);
insert into ay values(20, 30);
optimize table ay;
select * from ay;
insert into ay values(20, 30), (40, 10);
optimize table ay;
select * from ay;
drop table if exists ay;