2021-02-04 03:49:28 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionDeltaSum.h>
|
|
|
|
|
|
|
|
#include <AggregateFunctions/AggregateFunctionFactory.h>
|
|
|
|
#include <AggregateFunctions/FactoryHelpers.h>
|
|
|
|
#include <AggregateFunctions/Helpers.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
2021-05-26 11:32:14 +00:00
|
|
|
struct Settings;
|
2021-02-04 03:49:28 +00:00
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
2021-02-04 19:28:45 +00:00
|
|
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
2021-02-04 03:49:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
AggregateFunctionPtr createAggregateFunctionDeltaSum(
|
|
|
|
const String & name,
|
|
|
|
const DataTypes & arguments,
|
2021-05-26 11:32:14 +00:00
|
|
|
const Array & params,
|
|
|
|
const Settings *)
|
2021-02-04 03:49:28 +00:00
|
|
|
{
|
|
|
|
assertNoParameters(name, params);
|
|
|
|
|
|
|
|
if (arguments.size() != 1)
|
|
|
|
throw Exception("Incorrect number of arguments for aggregate function " + name,
|
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
|
|
|
|
2021-02-04 19:28:45 +00:00
|
|
|
DataTypePtr data_type = arguments[0];
|
|
|
|
|
2021-02-09 03:48:56 +00:00
|
|
|
if (isInteger(data_type) || isFloat(data_type))
|
|
|
|
return AggregateFunctionPtr(createWithNumericType<AggregationFunctionDeltaSum>(
|
|
|
|
*data_type, arguments, params));
|
|
|
|
else
|
2021-02-04 19:28:45 +00:00
|
|
|
throw Exception("Illegal type " + arguments[0]->getName() + " of argument for aggregate function " + name,
|
2021-02-09 03:48:56 +00:00
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
2021-02-04 03:49:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void registerAggregateFunctionDeltaSum(AggregateFunctionFactory & factory)
|
|
|
|
{
|
|
|
|
AggregateFunctionProperties properties = { .returns_default_when_only_null = true, .is_order_dependent = true };
|
|
|
|
|
|
|
|
factory.registerFunction("deltaSum", { createAggregateFunctionDeltaSum, properties });
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|