2019-06-12 07:46:36 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionResample.h>
|
|
|
|
|
|
|
|
#include <AggregateFunctions/AggregateFunctionCombinatorFactory.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
2019-06-25 04:28:07 +00:00
|
|
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
2019-06-12 07:46:36 +00:00
|
|
|
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
|
|
|
|
}
|
|
|
|
|
2019-06-25 10:17:11 +00:00
|
|
|
class AggregateFunctionCombinatorResample final : public IAggregateFunctionCombinator
|
2019-06-12 07:46:36 +00:00
|
|
|
{
|
|
|
|
public:
|
2019-06-14 13:20:21 +00:00
|
|
|
String getName() const override
|
|
|
|
{
|
2019-06-12 07:46:36 +00:00
|
|
|
return "Resample";
|
|
|
|
}
|
|
|
|
|
|
|
|
DataTypes transformArguments(const DataTypes & arguments) const override
|
|
|
|
{
|
|
|
|
if (arguments.empty())
|
2019-06-25 10:17:11 +00:00
|
|
|
throw Exception("Incorrect number of arguments for aggregate function with "
|
2019-06-12 07:46:36 +00:00
|
|
|
+ getName() + " suffix",
|
2019-06-25 10:17:11 +00:00
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
2019-06-12 07:46:36 +00:00
|
|
|
|
|
|
|
return DataTypes(arguments.begin(), arguments.end() - 1);
|
|
|
|
}
|
|
|
|
|
|
|
|
Array transformParameters(const Array & params) const override
|
|
|
|
{
|
|
|
|
if (params.size() < 3)
|
2019-06-25 10:17:11 +00:00
|
|
|
throw Exception("Incorrect number of parameters for aggregate function with "
|
2019-06-12 07:46:36 +00:00
|
|
|
+ getName() + " suffix",
|
2019-06-25 10:17:11 +00:00
|
|
|
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
|
2019-06-12 07:46:36 +00:00
|
|
|
|
|
|
|
return Array(params.begin(), params.end() - 3);
|
|
|
|
}
|
|
|
|
|
|
|
|
AggregateFunctionPtr transformAggregateFunction(
|
|
|
|
const AggregateFunctionPtr & nested_function,
|
|
|
|
const DataTypes & arguments,
|
2019-06-25 10:17:11 +00:00
|
|
|
const Array & params) const override
|
2019-06-12 07:46:36 +00:00
|
|
|
{
|
2019-06-25 10:17:11 +00:00
|
|
|
WhichDataType which{arguments.back()};
|
2019-06-12 07:46:36 +00:00
|
|
|
|
2019-06-25 04:28:07 +00:00
|
|
|
if (which.isNativeUInt() || which.isDateOrDateTime())
|
|
|
|
{
|
|
|
|
UInt64 begin = params[params.size() - 3].safeGet<UInt64>();
|
|
|
|
UInt64 end = params[params.size() - 2].safeGet<UInt64>();
|
2019-06-25 04:37:40 +00:00
|
|
|
|
2019-06-25 04:28:07 +00:00
|
|
|
UInt64 step = params[params.size() - 1].safeGet<UInt64>();
|
|
|
|
|
2019-06-12 07:46:36 +00:00
|
|
|
return std::make_shared<AggregateFunctionResample<UInt64>>(
|
|
|
|
nested_function,
|
2019-06-25 04:28:07 +00:00
|
|
|
begin,
|
|
|
|
end,
|
|
|
|
step,
|
2019-06-12 07:46:36 +00:00
|
|
|
arguments,
|
2019-06-25 10:17:11 +00:00
|
|
|
params);
|
2019-06-25 04:28:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if (which.isNativeInt() || which.isEnum() || which.isInterval())
|
|
|
|
{
|
2019-06-25 04:37:40 +00:00
|
|
|
Int64 begin, end;
|
2019-06-25 04:28:07 +00:00
|
|
|
|
|
|
|
// notice: UInt64 -> Int64 may lead to overflow
|
|
|
|
if (!params[params.size() - 3].tryGet<Int64>(begin))
|
|
|
|
begin = params[params.size() - 3].safeGet<UInt64>();
|
|
|
|
if (!params[params.size() - 2].tryGet<Int64>(end))
|
|
|
|
end = params[params.size() - 2].safeGet<UInt64>();
|
2019-06-25 04:37:40 +00:00
|
|
|
|
|
|
|
UInt64 step = params[params.size() - 1].safeGet<UInt64>();
|
2019-06-12 07:46:36 +00:00
|
|
|
|
|
|
|
return std::make_shared<AggregateFunctionResample<Int64>>(
|
|
|
|
nested_function,
|
2019-06-25 04:28:07 +00:00
|
|
|
begin,
|
|
|
|
end,
|
|
|
|
step,
|
2019-06-12 07:46:36 +00:00
|
|
|
arguments,
|
2019-06-25 10:17:11 +00:00
|
|
|
params);
|
2019-06-25 04:28:07 +00:00
|
|
|
}
|
2019-06-12 07:46:36 +00:00
|
|
|
|
2019-06-25 04:28:07 +00:00
|
|
|
throw Exception(
|
|
|
|
"Illegal types of argument for aggregate function " + getName()
|
2019-06-25 04:37:40 +00:00
|
|
|
+ ", the type of the last argument should be native integer or integer-like",
|
2019-06-25 10:17:11 +00:00
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
2019-06-12 07:46:36 +00:00
|
|
|
}
|
|
|
|
};
|
|
|
|
|
2019-06-25 10:17:11 +00:00
|
|
|
void registerAggregateFunctionCombinatorResample(AggregateFunctionCombinatorFactory & factory)
|
2019-06-12 07:46:36 +00:00
|
|
|
{
|
2019-06-25 10:17:11 +00:00
|
|
|
factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorResample>());
|
2019-06-12 07:46:36 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|