ClickHouse
55 строк · 1.5 Кб
1#include "AggregateFunctionForEach.h"
2#include "AggregateFunctionCombinatorFactory.h"
3
4#include <Common/typeid_cast.h>
5
6
7namespace DB
8{
9
10namespace ErrorCodes
11{
12extern const int ILLEGAL_TYPE_OF_ARGUMENT;
13}
14
15namespace
16{
17
18class AggregateFunctionCombinatorForEach final : public IAggregateFunctionCombinator
19{
20public:
21String getName() const override { return "ForEach"; }
22
23DataTypes transformArguments(const DataTypes & arguments) const override
24{
25DataTypes nested_arguments;
26for (const auto & type : arguments)
27{
28if (const DataTypeArray * array = typeid_cast<const DataTypeArray *>(type.get()))
29nested_arguments.push_back(array->getNestedType());
30else
31throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of argument for "
32"aggregate function with {} suffix. Must be array.", type->getName(), getName());
33}
34
35return nested_arguments;
36}
37
38AggregateFunctionPtr transformAggregateFunction(
39const AggregateFunctionPtr & nested_function,
40const AggregateFunctionProperties &,
41const DataTypes & arguments,
42const Array & params) const override
43{
44return std::make_shared<AggregateFunctionForEach>(nested_function, arguments, params);
45}
46};
47
48}
49
50void registerAggregateFunctionCombinatorForEach(AggregateFunctionCombinatorFactory & factory)
51{
52factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorForEach>());
53}
54
55}
56