ClickHouse/src/AggregateFunctions/AggregateFunctionResample.cpp

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

106 lines
3.2 KiB
C++
Raw Normal View History

#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;
extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
}
2020-09-07 18:00:37 +00:00
namespace
{
2019-06-25 10:17:11 +00:00
class AggregateFunctionCombinatorResample final : public IAggregateFunctionCombinator
{
public:
2019-06-14 13:20:21 +00:00
String getName() const override
{
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 "
+ getName() + " suffix",
2019-06-25 10:17:11 +00:00
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
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 "
+ getName() + " suffix",
2019-06-25 10:17:11 +00:00
ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH);
return Array(params.begin(), params.end() - 3);
}
AggregateFunctionPtr transformAggregateFunction(
const AggregateFunctionPtr & nested_function,
2020-06-14 07:44:02 +00:00
const AggregateFunctionProperties &,
const DataTypes & arguments,
2019-06-25 10:17:11 +00:00
const Array & params) const override
{
2019-06-25 10:17:11 +00:00
WhichDataType which{arguments.back()};
if (which.isNativeUInt() || which.isDate() || which.isDateTime() || which.isDateTime64())
2019-06-25 04:28:07 +00:00
{
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>();
return std::make_shared<AggregateFunctionResample<UInt64>>(
nested_function,
2019-06-25 04:28:07 +00:00
begin,
end,
step,
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>();
return std::make_shared<AggregateFunctionResample<Int64>>(
nested_function,
2019-06-25 04:28:07 +00:00
begin,
end,
step,
arguments,
2019-06-25 10:17:11 +00:00
params);
2019-06-25 04:28:07 +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);
}
};
2020-09-07 18:00:37 +00:00
}
2019-06-25 10:17:11 +00:00
void registerAggregateFunctionCombinatorResample(AggregateFunctionCombinatorFactory & factory)
{
2019-06-25 10:17:11 +00:00
factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorResample>());
}
}