ClickHouse/dbms/src/AggregateFunctions/AggregateFunctionStatistics.cpp

60 lines
2.5 KiB
C++
Raw Normal View History

#include <AggregateFunctions/AggregateFunctionFactory.h>
#include <AggregateFunctions/Helpers.h>
#include <AggregateFunctions/FactoryHelpers.h>
#include <AggregateFunctions/AggregateFunctionStatistics.h>
2015-09-24 12:40:36 +00:00
2015-09-24 12:40:36 +00:00
namespace DB
{
namespace ErrorCodes
{
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
}
2015-09-24 12:40:36 +00:00
namespace
{
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
{
assertNoParameters(name, parameters);
assertUnary(name, argument_types);
2015-09-24 12:40:36 +00:00
2019-02-11 19:26:32 +00:00
AggregateFunctionPtr res(createWithNumericType<FunctionTemplate>(*argument_types[0], argument_types[0]));
2015-09-24 12:40:36 +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
return res;
2015-09-24 12:40:36 +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
{
assertNoParameters(name, parameters);
assertBinary(name, argument_types);
2015-09-24 12:40:36 +00:00
2019-02-11 19:26:32 +00:00
AggregateFunctionPtr res(createWithTwoNumericTypes<FunctionTemplate>(*argument_types[0], *argument_types[1], argument_types));
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
return res;
2015-09-24 12:40:36 +00:00
}
}
void registerAggregateFunctionsStatisticsStable(AggregateFunctionFactory & factory)
2015-09-24 12:40:36 +00:00
{
factory.registerFunction("varSampStable", createAggregateFunctionStatisticsUnary<AggregateFunctionVarSampStable>);
factory.registerFunction("varPopStable", createAggregateFunctionStatisticsUnary<AggregateFunctionVarPopStable>);
factory.registerFunction("stddevSampStable", createAggregateFunctionStatisticsUnary<AggregateFunctionStddevSampStable>);
factory.registerFunction("stddevPopStable", createAggregateFunctionStatisticsUnary<AggregateFunctionStddevPopStable>);
factory.registerFunction("covarSampStable", createAggregateFunctionStatisticsBinary<AggregateFunctionCovarSampStable>);
factory.registerFunction("covarPopStable", createAggregateFunctionStatisticsBinary<AggregateFunctionCovarPopStable>);
factory.registerFunction("corrStable", createAggregateFunctionStatisticsBinary<AggregateFunctionCorrStable>);
2015-09-24 12:40:36 +00:00
}
}