mirror of
https://github.com/ClickHouse/ClickHouse.git
synced 2024-10-01 06:00:49 +00:00
32 lines
881 B
C++
32 lines
881 B
C++
|
#include <DB/AggregateFunctions/AggregateFunctionFactory.h>
|
||
|
#include <DB/AggregateFunctions/AggregateFunctionAvg.h>
|
||
|
#include <DB/AggregateFunctions/Helpers.h>
|
||
|
|
||
|
namespace DB
|
||
|
{
|
||
|
|
||
|
namespace
|
||
|
{
|
||
|
|
||
|
AggregateFunctionPtr createAggregateFunctionAvg(const std::string & name, const DataTypes & argument_types)
|
||
|
{
|
||
|
if (argument_types.size() != 1)
|
||
|
throw Exception("Incorrect number of arguments for aggregate function " + name, ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
||
|
|
||
|
AggregateFunctionPtr res = createWithNumericType<AggregateFunctionAvg>(*argument_types[0]);
|
||
|
|
||
|
if (!res)
|
||
|
throw Exception("Illegal type " + argument_types[0]->getName() + " of argument for aggregate function " + name, ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
||
|
|
||
|
return res;
|
||
|
}
|
||
|
|
||
|
}
|
||
|
|
||
|
void registerAggregateFunctionAvg(AggregateFunctionFactory & factory)
|
||
|
{
|
||
|
factory.registerFunction({"avg"}, createAggregateFunctionAvg);
|
||
|
}
|
||
|
|
||
|
}
|