2017-04-01 09:19:00 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionState.h>
|
2017-05-03 19:46:41 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionMerge.h>
|
2017-12-24 06:50:11 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionCombinatorFactory.h>
|
|
|
|
#include <DataTypes/DataTypeAggregateFunction.h>
|
|
|
|
|
2015-09-24 12:40:36 +00:00
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-05-03 19:46:41 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2017-12-24 06:50:11 +00:00
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
2017-05-03 19:46:41 +00:00
|
|
|
extern const int BAD_ARGUMENTS;
|
|
|
|
}
|
|
|
|
|
2017-12-24 06:50:11 +00:00
|
|
|
class AggregateFunctionCombinatorState final : public IAggregateFunctionCombinator
|
|
|
|
{
|
|
|
|
public:
|
2018-06-03 20:39:06 +00:00
|
|
|
String getName() const override { return "State"; }
|
2017-12-24 06:50:11 +00:00
|
|
|
|
|
|
|
DataTypes transformArguments(const DataTypes & arguments) const override
|
|
|
|
{
|
|
|
|
return arguments;
|
|
|
|
}
|
|
|
|
|
|
|
|
AggregateFunctionPtr transformAggregateFunction(
|
|
|
|
const AggregateFunctionPtr & nested_function, const DataTypes & arguments, const Array & params) const override
|
|
|
|
{
|
|
|
|
return std::make_shared<AggregateFunctionState>(nested_function, arguments, params);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
void registerAggregateFunctionCombinatorState(AggregateFunctionCombinatorFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorState>());
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2017-05-03 19:46:41 +00:00
|
|
|
DataTypePtr AggregateFunctionState::getReturnType() const
|
|
|
|
{
|
2017-12-20 07:36:30 +00:00
|
|
|
auto ptr = std::make_shared<DataTypeAggregateFunction>(nested_func, arguments, params);
|
2017-05-03 19:46:41 +00:00
|
|
|
|
2017-12-24 06:50:11 +00:00
|
|
|
/// Special case: it is -MergeState combinator.
|
|
|
|
/// We must return AggregateFunction(agg, ...) instead of AggregateFunction(aggMerge, ...)
|
2017-05-03 19:46:41 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|