2017-04-01 09:19:00 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionFactory.h>
|
|
|
|
#include <AggregateFunctions/Helpers.h>
|
2017-12-20 20:25:22 +00:00
|
|
|
#include <AggregateFunctions/FactoryHelpers.h>
|
2017-07-12 01:16:01 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionStatistics.h>
|
2015-09-24 12:40:36 +00:00
|
|
|
|
2017-12-20 20:25:22 +00:00
|
|
|
|
2015-09-24 12:40:36 +00:00
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
2017-12-20 20:25:22 +00:00
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
2015-09-24 12:40:36 +00:00
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
2017-12-20 20:58:43 +00:00
|
|
|
template <template <typename> class FunctionTemplate>
|
|
|
|
AggregateFunctionPtr createAggregateFunctionStatisticsUnary(const std::string & name, const DataTypes & argument_types, const Array & parameters)
|
2015-09-24 12:40:36 +00:00
|
|
|
{
|
2017-12-20 20:25:22 +00:00
|
|
|
assertNoParameters(name, parameters);
|
|
|
|
assertUnary(name, argument_types);
|
2015-09-24 12:40:36 +00:00
|
|
|
|
2017-12-20 20:58:43 +00:00
|
|
|
AggregateFunctionPtr res(createWithNumericType<FunctionTemplate>(*argument_types[0]));
|
2015-09-24 12:40:36 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!res)
|
|
|
|
throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
2015-09-24 12:40:36 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
2017-12-20 20:58:43 +00:00
|
|
|
template <template <typename, typename> class FunctionTemplate>
|
|
|
|
AggregateFunctionPtr createAggregateFunctionStatisticsBinary(const std::string & name, const DataTypes & argument_types, const Array & parameters)
|
2015-09-24 12:40:36 +00:00
|
|
|
{
|
2017-12-20 20:25:22 +00:00
|
|
|
assertNoParameters(name, parameters);
|
|
|
|
assertBinary(name, argument_types);
|
2015-09-24 12:40:36 +00:00
|
|
|
|
2017-12-20 20:58:43 +00:00
|
|
|
AggregateFunctionPtr res(createWithTwoNumericTypes<FunctionTemplate>(*argument_types[0], *argument_types[1]));
|
2017-04-01 07:20:54 +00:00
|
|
|
if (!res)
|
|
|
|
throw Exception("Illegal types " + argument_types[0]->getName() + " and " + argument_types[1]->getName()
|
|
|
|
+ " of arguments for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
2015-09-24 12:40:36 +00:00
|
|
|
|
2017-04-01 07:20:54 +00:00
|
|
|
return res;
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerAggregateFunctionsStatistics(AggregateFunctionFactory & factory)
|
|
|
|
{
|
2017-12-20 20:58:43 +00:00
|
|
|
factory.registerFunction("varSamp", createAggregateFunctionStatisticsUnary<AggregateFunctionVarSamp>);
|
|
|
|
factory.registerFunction("varPop", createAggregateFunctionStatisticsUnary<AggregateFunctionVarPop>);
|
|
|
|
factory.registerFunction("stddevSamp", createAggregateFunctionStatisticsUnary<AggregateFunctionStdDevSamp>);
|
|
|
|
factory.registerFunction("stddevPop", createAggregateFunctionStatisticsUnary<AggregateFunctionStdDevPop>);
|
|
|
|
factory.registerFunction("covarSamp", createAggregateFunctionStatisticsBinary<AggregateFunctionCovarSamp>);
|
|
|
|
factory.registerFunction("covarPop", createAggregateFunctionStatisticsBinary<AggregateFunctionCovarPop>);
|
|
|
|
factory.registerFunction("corr", createAggregateFunctionStatisticsBinary<AggregateFunctionCorr>, AggregateFunctionFactory::CaseInsensitive);
|
2017-04-01 07:20:54 +00:00
|
|
|
|
|
|
|
/// Synonims for compatibility.
|
2017-12-20 20:58:43 +00:00
|
|
|
factory.registerFunction("VAR_SAMP", createAggregateFunctionStatisticsUnary<AggregateFunctionVarSamp>, AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
factory.registerFunction("VAR_POP", createAggregateFunctionStatisticsUnary<AggregateFunctionVarPop>, AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
factory.registerFunction("STDDEV_SAMP", createAggregateFunctionStatisticsUnary<AggregateFunctionStdDevSamp>, AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
factory.registerFunction("STDDEV_POP", createAggregateFunctionStatisticsUnary<AggregateFunctionStdDevPop>, AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
factory.registerFunction("COVAR_SAMP", createAggregateFunctionStatisticsBinary<AggregateFunctionCovarSamp>, AggregateFunctionFactory::CaseInsensitive);
|
|
|
|
factory.registerFunction("COVAR_POP", createAggregateFunctionStatisticsBinary<AggregateFunctionCovarPop>, AggregateFunctionFactory::CaseInsensitive);
|
2015-09-24 12:40:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|