ClickHouse
81 строка · 2.7 Кб
1#include "AggregateFunctionMerge.h"2#include "AggregateFunctionCombinatorFactory.h"3
4#include <DataTypes/DataTypeAggregateFunction.h>5
6namespace DB7{
8
9namespace ErrorCodes10{
11extern const int ILLEGAL_TYPE_OF_ARGUMENT;12extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;13}
14
15namespace
16{
17
18class AggregateFunctionCombinatorMerge final : public IAggregateFunctionCombinator19{
20public:21String getName() const override { return "Merge"; }22
23DataTypes transformArguments(const DataTypes & arguments) const override24{25if (arguments.size() != 1)26throw Exception(27ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH,28"Incorrect number of arguments for aggregate function with {} suffix",29getName());30
31const DataTypePtr & argument = arguments[0];32
33const DataTypeAggregateFunction * function = typeid_cast<const DataTypeAggregateFunction *>(argument.get());34if (!function)35throw Exception(36ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,37"Illegal type {} of argument for aggregate function with {} suffix. It must be AggregateFunction(...)",38argument->getName(),39getName());40
41return function->getArgumentsDataTypes();42}43
44AggregateFunctionPtr transformAggregateFunction(45const AggregateFunctionPtr & nested_function,46const AggregateFunctionProperties &,47const DataTypes & arguments,48const Array & params) const override49{50const DataTypePtr & argument = arguments[0];51
52const DataTypeAggregateFunction * function = typeid_cast<const DataTypeAggregateFunction *>(argument.get());53if (!function)54throw Exception(55ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,56"Illegal type {} of argument for aggregate function with {} suffix. It must be AggregateFunction(...)",57argument->getName(),58getName());59
60if (!nested_function->haveSameStateRepresentation(*function->getFunction()))61throw Exception(62ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,63"Illegal type {} of argument for aggregate function with {} suffix. because it corresponds to different aggregate "64"function: {} instead of {}",65argument->getName(),66getName(),67function->getFunctionName(),68nested_function->getName());69
70return std::make_shared<AggregateFunctionMerge>(nested_function, argument, params);71}72};73
74}
75
76void registerAggregateFunctionCombinatorMerge(AggregateFunctionCombinatorFactory & factory)77{
78factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorMerge>());79}
80
81}
82