| 1 | #include <AggregateFunctions/AggregateFunctionFactory.h> |
| 2 | #include <AggregateFunctions/Helpers.h> |
| 3 | #include <AggregateFunctions/FactoryHelpers.h> |
| 4 | #include <AggregateFunctions/AggregateFunctionStatistics.h> |
| 5 | #include "registerAggregateFunctions.h" |
| 6 | |
| 7 | |
| 8 | namespace DB |
| 9 | { |
| 10 | |
| 11 | namespace ErrorCodes |
| 12 | { |
| 13 | extern const int ILLEGAL_TYPE_OF_ARGUMENT; |
| 14 | } |
| 15 | |
| 16 | namespace |
| 17 | { |
| 18 | |
| 19 | template <template <typename> class FunctionTemplate> |
| 20 | AggregateFunctionPtr createAggregateFunctionStatisticsUnary(const std::string & name, const DataTypes & argument_types, const Array & parameters) |
| 21 | { |
| 22 | assertNoParameters(name, parameters); |
| 23 | assertUnary(name, argument_types); |
| 24 | |
| 25 | AggregateFunctionPtr res(createWithNumericType<FunctionTemplate>(*argument_types[0], argument_types[0])); |
| 26 | |
| 27 | if (!res) |
| 28 | throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
| 29 | |
| 30 | return res; |
| 31 | } |
| 32 | |
| 33 | template <template <typename, typename> class FunctionTemplate> |
| 34 | AggregateFunctionPtr createAggregateFunctionStatisticsBinary(const std::string & name, const DataTypes & argument_types, const Array & parameters) |
| 35 | { |
| 36 | assertNoParameters(name, parameters); |
| 37 | assertBinary(name, argument_types); |
| 38 | |
| 39 | AggregateFunctionPtr res(createWithTwoNumericTypes<FunctionTemplate>(*argument_types[0], *argument_types[1], argument_types)); |
| 40 | if (!res) |
| 41 | throw Exception("Illegal types " + argument_types[0]->getName() + " and " + argument_types[1]->getName() |
| 42 | + " of arguments for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
| 43 | |
| 44 | return res; |
| 45 | } |
| 46 | |
| 47 | } |
| 48 | |
| 49 | void registerAggregateFunctionsStatisticsStable(AggregateFunctionFactory & factory) |
| 50 | { |
| 51 | factory.registerFunction("varSampStable" , createAggregateFunctionStatisticsUnary<AggregateFunctionVarSampStable>); |
| 52 | factory.registerFunction("varPopStable" , createAggregateFunctionStatisticsUnary<AggregateFunctionVarPopStable>); |
| 53 | factory.registerFunction("stddevSampStable" , createAggregateFunctionStatisticsUnary<AggregateFunctionStddevSampStable>); |
| 54 | factory.registerFunction("stddevPopStable" , createAggregateFunctionStatisticsUnary<AggregateFunctionStddevPopStable>); |
| 55 | factory.registerFunction("covarSampStable" , createAggregateFunctionStatisticsBinary<AggregateFunctionCovarSampStable>); |
| 56 | factory.registerFunction("covarPopStable" , createAggregateFunctionStatisticsBinary<AggregateFunctionCovarPopStable>); |
| 57 | factory.registerFunction("corrStable" , createAggregateFunctionStatisticsBinary<AggregateFunctionCorrStable>); |
| 58 | } |
| 59 | |
| 60 | } |
| 61 | |