| 1 | #include <AggregateFunctions/AggregateFunctionFactory.h> |
| 2 | #include <AggregateFunctions/Helpers.h> |
| 3 | #include <AggregateFunctions/FactoryHelpers.h> |
| 4 | #include <AggregateFunctions/AggregateFunctionStatisticsSimple.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; |
| 26 | DataTypePtr data_type = argument_types[0]; |
| 27 | if (isDecimal(data_type)) |
| 28 | res.reset(createWithDecimalType<FunctionTemplate>(*data_type, *data_type, argument_types)); |
| 29 | else |
| 30 | res.reset(createWithNumericType<FunctionTemplate>(*data_type, argument_types)); |
| 31 | |
| 32 | if (!res) |
| 33 | throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, |
| 34 | ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
| 35 | return res; |
| 36 | } |
| 37 | |
| 38 | template <template <typename, typename> class FunctionTemplate> |
| 39 | AggregateFunctionPtr createAggregateFunctionStatisticsBinary(const std::string & name, const DataTypes & argument_types, const Array & parameters) |
| 40 | { |
| 41 | assertNoParameters(name, parameters); |
| 42 | assertBinary(name, argument_types); |
| 43 | |
| 44 | AggregateFunctionPtr res(createWithTwoNumericTypes<FunctionTemplate>(*argument_types[0], *argument_types[1], argument_types)); |
| 45 | if (!res) |
| 46 | throw Exception("Illegal types " + argument_types[0]->getName() + " and " + argument_types[1]->getName() |
| 47 | + " of arguments for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT); |
| 48 | |
| 49 | return res; |
| 50 | } |
| 51 | |
| 52 | } |
| 53 | |
| 54 | void registerAggregateFunctionsStatisticsSimple(AggregateFunctionFactory & factory) |
| 55 | { |
| 56 | factory.registerFunction("varSamp" , createAggregateFunctionStatisticsUnary<AggregateFunctionVarSampSimple>); |
| 57 | factory.registerFunction("varPop" , createAggregateFunctionStatisticsUnary<AggregateFunctionVarPopSimple>); |
| 58 | factory.registerFunction("stddevSamp" , createAggregateFunctionStatisticsUnary<AggregateFunctionStddevSampSimple>); |
| 59 | factory.registerFunction("stddevPop" , createAggregateFunctionStatisticsUnary<AggregateFunctionStddevPopSimple>); |
| 60 | factory.registerFunction("skewSamp" , createAggregateFunctionStatisticsUnary<AggregateFunctionSkewSampSimple>); |
| 61 | factory.registerFunction("skewPop" , createAggregateFunctionStatisticsUnary<AggregateFunctionSkewPopSimple>); |
| 62 | factory.registerFunction("kurtSamp" , createAggregateFunctionStatisticsUnary<AggregateFunctionKurtSampSimple>); |
| 63 | factory.registerFunction("kurtPop" , createAggregateFunctionStatisticsUnary<AggregateFunctionKurtPopSimple>); |
| 64 | |
| 65 | factory.registerFunction("covarSamp" , createAggregateFunctionStatisticsBinary<AggregateFunctionCovarSampSimple>); |
| 66 | factory.registerFunction("covarPop" , createAggregateFunctionStatisticsBinary<AggregateFunctionCovarPopSimple>); |
| 67 | factory.registerFunction("corr" , createAggregateFunctionStatisticsBinary<AggregateFunctionCorrSimple>, AggregateFunctionFactory::CaseInsensitive); |
| 68 | |
| 69 | /// Synonims for compatibility. |
| 70 | factory.registerAlias("VAR_SAMP" , "varSamp" , AggregateFunctionFactory::CaseInsensitive); |
| 71 | factory.registerAlias("VAR_POP" , "varPop" , AggregateFunctionFactory::CaseInsensitive); |
| 72 | factory.registerAlias("STDDEV_SAMP" , "stddevSamp" , AggregateFunctionFactory::CaseInsensitive); |
| 73 | factory.registerAlias("STDDEV_POP" , "stddevPop" , AggregateFunctionFactory::CaseInsensitive); |
| 74 | factory.registerAlias("COVAR_SAMP" , "covarSamp" , AggregateFunctionFactory::CaseInsensitive); |
| 75 | factory.registerAlias("COVAR_POP" , "covarPop" , AggregateFunctionFactory::CaseInsensitive); |
| 76 | } |
| 77 | |
| 78 | } |
| 79 | |