1 | #include <AggregateFunctions/AggregateFunctionFactory.h> |
2 | #include <AggregateFunctions/AggregateFunctionWindowFunnel.h> |
3 | #include <AggregateFunctions/Helpers.h> |
4 | #include <AggregateFunctions/FactoryHelpers.h> |
5 | #include <DataTypes/DataTypeDate.h> |
6 | #include <DataTypes/DataTypeDateTime.h> |
7 | |
8 | #include <ext/range.h> |
9 | #include "registerAggregateFunctions.h" |
10 | |
11 | |
12 | namespace DB |
13 | { |
14 | |
15 | namespace |
16 | { |
17 | |
18 | template <template <typename> class Data> |
19 | AggregateFunctionPtr createAggregateFunctionWindowFunnel(const std::string & name, const DataTypes & arguments, const Array & params) |
20 | { |
21 | if (params.size() < 1) |
22 | throw Exception{"Aggregate function " + name + " requires at least one parameter: <window>, [option, [option, ...]]" , ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH}; |
23 | |
24 | if (arguments.size() < 2) |
25 | throw Exception("Aggregate function " + name + " requires one timestamp argument and at least one event condition." , ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); |
26 | |
27 | if (arguments.size() > max_events + 1) |
28 | throw Exception("Too many event arguments for aggregate function " + name, ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH); |
29 | |
30 | for (const auto i : ext::range(1, arguments.size())) |
31 | { |
32 | auto cond_arg = arguments[i].get(); |
33 | if (!isUInt8(cond_arg)) |
34 | throw Exception{"Illegal type " + cond_arg->getName() + " of argument " + toString(i + 1) + " of aggregate function " |
35 | + name + ", must be UInt8" , ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT}; |
36 | } |
37 | |
38 | AggregateFunctionPtr res(createWithUnsignedIntegerType<AggregateFunctionWindowFunnel, Data>(*arguments[0], arguments, params)); |
39 | WhichDataType which(arguments.front().get()); |
40 | if (res) |
41 | return res; |
42 | else if (which.isDate()) |
43 | return std::make_shared<AggregateFunctionWindowFunnel<DataTypeDate::FieldType, Data<DataTypeDate::FieldType>>>(arguments, params); |
44 | else if (which.isDateTime()) |
45 | return std::make_shared<AggregateFunctionWindowFunnel<DataTypeDateTime::FieldType, Data<DataTypeDateTime::FieldType>>>(arguments, params); |
46 | |
47 | throw Exception{"Illegal type " + arguments.front().get()->getName() |
48 | + " of first argument of aggregate function " + name + ", must be Unsigned Number, Date, DateTime" , |
49 | ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT}; |
50 | } |
51 | |
52 | } |
53 | |
54 | void registerAggregateFunctionWindowFunnel(AggregateFunctionFactory & factory) |
55 | { |
56 | factory.registerFunction("windowFunnel" , createAggregateFunctionWindowFunnel<AggregateFunctionWindowFunnelData>, AggregateFunctionFactory::CaseInsensitive); |
57 | } |
58 | |
59 | } |
60 | |