1#include <AggregateFunctions/AggregateFunctionIf.h>
2#include <AggregateFunctions/AggregateFunctionCombinatorFactory.h>
3#include "registerAggregateFunctions.h"
4
5
6namespace DB
7{
8
9namespace ErrorCodes
10{
11 extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
12}
13
14class AggregateFunctionCombinatorIf final : public IAggregateFunctionCombinator
15{
16public:
17 String getName() const override { return "If"; }
18
19 DataTypes transformArguments(const DataTypes & arguments) const override
20 {
21 if (arguments.empty())
22 throw Exception("Incorrect number of arguments for aggregate function with " + getName() + " suffix",
23 ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
24
25 if (!isUInt8(arguments.back()))
26 throw Exception("Illegal type " + arguments.back()->getName() + " of last argument for aggregate function with " + getName() + " suffix",
27 ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
28
29 return DataTypes(arguments.begin(), std::prev(arguments.end()));
30 }
31
32 AggregateFunctionPtr transformAggregateFunction(
33 const AggregateFunctionPtr & nested_function, const DataTypes & arguments, const Array &) const override
34 {
35 return std::make_shared<AggregateFunctionIf>(nested_function, arguments);
36 }
37};
38
39void registerAggregateFunctionCombinatorIf(AggregateFunctionCombinatorFactory & factory)
40{
41 factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorIf>());
42}
43
44}
45