Combinator -MergeState now returns AggregateFunction(nested_func). [#CLICKHOUSE-2891]

This commit is contained in:
Vitaliy Lyudvichenko 2017-05-03 22:46:41 +03:00 committed by alexey-milovidov
parent 713168c98f
commit 6d93d9cefb
5 changed files with 53 additions and 4 deletions

View File

@ -34,6 +34,11 @@ public:
return nested_func->getReturnType(); return nested_func->getReturnType();
} }
AggregateFunctionPtr getNestedFunction() const
{
return nested_func_owner;
}
void setArguments(const DataTypes & arguments) override void setArguments(const DataTypes & arguments) override
{ {
if (arguments.size() != 1) if (arguments.size() != 1)

View File

@ -1,8 +1,34 @@
#include <AggregateFunctions/AggregateFunctionState.h> #include <AggregateFunctions/AggregateFunctionState.h>
#include <AggregateFunctions/AggregateFunctionMerge.h>
namespace DB namespace DB
{ {
namespace ErrorCodes
{
extern const int BAD_ARGUMENTS;
}
DataTypePtr AggregateFunctionState::getReturnType() const
{
auto ptr = std::make_shared<DataTypeAggregateFunction>(nested_func_owner, arguments, params);
/// Special case: it is -MergeState combinator
if (typeid_cast<const AggregateFunctionMerge *>(ptr->getFunction().get()))
{
if (arguments.size() != 1)
throw Exception("Combinator -MergeState expects only one argument", ErrorCodes::BAD_ARGUMENTS);
if (!typeid_cast<const DataTypeAggregateFunction *>(arguments[0].get()))
throw Exception("Combinator -MergeState expects argument with AggregateFunction type", ErrorCodes::BAD_ARGUMENTS);
return arguments[0];
}
return ptr;
}
AggregateFunctionPtr createAggregateFunctionState(AggregateFunctionPtr & nested) AggregateFunctionPtr createAggregateFunctionState(AggregateFunctionPtr & nested)
{ {
return std::make_shared<AggregateFunctionState>(nested); return std::make_shared<AggregateFunctionState>(nested);

View File

@ -1,3 +1,4 @@
#pragma once #pragma once
#include <DataTypes/DataTypeAggregateFunction.h> #include <DataTypes/DataTypeAggregateFunction.h>
@ -30,10 +31,7 @@ public:
return nested_func->getName() + "State"; return nested_func->getName() + "State";
} }
DataTypePtr getReturnType() const override DataTypePtr getReturnType() const override;
{
return std::make_shared<DataTypeAggregateFunction>(nested_func_owner, arguments, params);
}
void setArguments(const DataTypes & arguments_) override void setArguments(const DataTypes & arguments_) override
{ {

View File

@ -38,3 +38,20 @@ SELECT arrayReduce('groupUniqArrayMergeIf',
SELECT ''; SELECT '';
SELECT arrayReduce('avgState', [0]) IN (arrayReduce('avgState', [0, 1]), arrayReduce('avgState', [0])); SELECT arrayReduce('avgState', [0]) IN (arrayReduce('avgState', [0, 1]), arrayReduce('avgState', [0]));
SELECT arrayReduce('avgState', [0]) IN (arrayReduce('avgState', [0, 1]), arrayReduce('avgState', [1])); SELECT arrayReduce('avgState', [0]) IN (arrayReduce('avgState', [0, 1]), arrayReduce('avgState', [1]));
SELECT '';
SELECT arrayReduce('uniqExactMerge',
[arrayReduce('uniqExactMergeState',
[
arrayReduce('uniqExactState', [12345678901]),
arrayReduce('uniqExactState', [12345678901])
])
]);
SELECT arrayReduce('uniqExactMerge',
[arrayReduce('uniqExactMergeState',
[
arrayReduce('uniqExactState', [12345678901]),
arrayReduce('uniqExactState', [12345678902])
])
]);