1 | #include <AggregateFunctions/AggregateFunctionArray.h> |
---|---|
2 | #include <AggregateFunctions/AggregateFunctionCombinatorFactory.h> |
3 | #include <Common/typeid_cast.h> |
4 | #include "registerAggregateFunctions.h" |
5 | |
6 | namespace DB |
7 | { |
8 | |
9 | namespace ErrorCodes |
10 | { |
11 | extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; |
12 | extern const int ILLEGAL_TYPE_OF_ARGUMENT; |
13 | } |
14 | |
15 | class AggregateFunctionCombinatorArray final : public IAggregateFunctionCombinator |
16 | { |
17 | public: |
18 | String getName() const override { return "Array"; } |
19 | |
20 | DataTypes transformArguments(const DataTypes & arguments) const override |
21 | { |
22 | if (0 == arguments.size()) |
23 | throw Exception("-Array aggregate functions require at least one argument", ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); |
24 | |
25 | DataTypes nested_arguments; |
26 | for (const auto & type : arguments) |
27 | { |
28 | if (const DataTypeArray * array = typeid_cast<const DataTypeArray *>(type.get())) |
29 | nested_arguments.push_back(array->getNestedType()); |
30 | else |
31 | throw Exception("Illegal type "+ type->getName() + " of argument" |
32 | " for aggregate function with "+ getName() + " suffix. Must be array.", ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
33 | } |
34 | |
35 | return nested_arguments; |
36 | } |
37 | |
38 | AggregateFunctionPtr transformAggregateFunction( |
39 | const AggregateFunctionPtr & nested_function, const DataTypes & arguments, const Array &) const override |
40 | { |
41 | return std::make_shared<AggregateFunctionArray>(nested_function, arguments); |
42 | } |
43 | }; |
44 | |
45 | void registerAggregateFunctionCombinatorArray(AggregateFunctionCombinatorFactory & factory) |
46 | { |
47 | factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorArray>()); |
48 | } |
49 | |
50 | } |
51 |