2017-12-22 22:23:03 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionFactory.h>
|
|
|
|
#include <AggregateFunctions/Helpers.h>
|
|
|
|
#include <AggregateFunctions/FactoryHelpers.h>
|
|
|
|
#include <AggregateFunctions/AggregateFunctionStatisticsSimple.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
template <template <typename> class FunctionTemplate>
|
|
|
|
AggregateFunctionPtr createAggregateFunctionStatisticsUnary(const std::string & name, const DataTypes & argument_types, const Array & parameters)
|
|
|
|
{
|
|
|
|
assertNoParameters(name, parameters);
|
|
|
|
assertUnary(name, argument_types);
|
|
|
|
|
2018-09-13 18:36:47 +00:00
|
|
|
AggregateFunctionPtr res;
|
|
|
|
DataTypePtr data_type = argument_types[0];
|
|
|
|
if (isDecimal(data_type))
|
|
|
|
{
|
|
|
|
res.reset(createWithDecimalType<FunctionTemplate>(*data_type));
|
|
|
|
}
|
|
|
|
else
|
|
|
|
res.reset(createWithNumericType<FunctionTemplate>(*data_type));
|
2017-12-22 22:23:03 +00:00
|
|
|
|
2017-12-22 22:59:45 +00:00
|
|
|
if (!res)
|
2018-09-13 18:36:47 +00:00
|
|
|
throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name,
|
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
2017-12-22 22:59:45 +00:00
|
|
|
return res;
|
2017-12-22 22:23:03 +00:00
|
|
|
}
|
|
|
|
|
2017-12-22 22:59:45 +00:00
|
|
|
template <template <typename, typename> class FunctionTemplate>
|
2017-12-22 22:23:03 +00:00
|
|
|
AggregateFunctionPtr createAggregateFunctionStatisticsBinary(const std::string & name, const DataTypes & argument_types, const Array & parameters)
|
|
|
|
{
|
|
|
|
assertNoParameters(name, parameters);
|
|
|
|
assertBinary(name, argument_types);
|
|
|
|
|
2017-12-22 22:59:45 +00:00
|
|
|
AggregateFunctionPtr res(createWithTwoNumericTypes<FunctionTemplate>(*argument_types[0], *argument_types[1]));
|
|
|
|
if (!res)
|
2017-12-22 22:23:03 +00:00
|
|
|
throw Exception("Illegal types " + argument_types[0]->getName() + " and " + argument_types[1]->getName()
|
2017-12-22 22:59:45 +00:00
|
|
|
+ " of arguments for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
2017-12-22 22:23:03 +00:00
|
|
|
|
2017-12-22 22:59:45 +00:00
|
|
|
return res;
|
2017-12-22 22:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerAggregateFunctionsStatisticsSimple(AggregateFunctionFactory & factory)
|
|
|
|
{
|
|
|
|
factory.registerFunction("varSamp", createAggregateFunctionStatisticsUnary<AggregateFunctionVarSampSimple>);
|
|
|
|
factory.registerFunction("varPop", createAggregateFunctionStatisticsUnary<AggregateFunctionVarPopSimple>);
|
|
|
|
factory.registerFunction("stddevSamp", createAggregateFunctionStatisticsUnary<AggregateFunctionStddevSampSimple>);
|
|
|
|
factory.registerFunction("stddevPop", createAggregateFunctionStatisticsUnary<AggregateFunctionStddevPopSimple>);
|
2018-09-13 18:36:47 +00:00
|
|
|
|
2017-12-22 22:23:03 +00:00
|
|
|
factory.registerFunction("covarSamp", createAggregateFunctionStatisticsBinary<AggregateFunctionCovarSampSimple>);
|
|
|
|
factory.registerFunction("covarPop", createAggregateFunctionStatisticsBinary<AggregateFunctionCovarPopSimple>);
|
|
|
|
factory.registerFunction("corr", createAggregateFunctionStatisticsBinary<AggregateFunctionCorrSimple>, AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
|
|
|
|
/// Synonims for compatibility.
|
2018-07-25 16:08:23 +00:00
|
|
|
factory.registerAlias("VAR_SAMP", "varSamp", AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
factory.registerAlias("VAR_POP", "varPop", AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
factory.registerAlias("STDDEV_SAMP", "stddevSamp", AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
factory.registerAlias("STDDEV_POP", "stddevPop", AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
factory.registerAlias("COVAR_SAMP", "covarSamp", AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
factory.registerAlias("COVAR_POP", "covarPop", AggregateFunctionFactory::CaseInsensitive);
|
2017-12-22 22:23:03 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|