2022-09-11 06:46:05 +00:00
|
|
|
#include <AggregateFunctions/AggregateFunctionQuantile.h>
|
|
|
|
#include <AggregateFunctions/QuantileTiming.h>
|
|
|
|
#include <AggregateFunctions/AggregateFunctionFactory.h>
|
|
|
|
#include <AggregateFunctions/Helpers.h>
|
|
|
|
#include <DataTypes/DataTypeDate.h>
|
|
|
|
#include <DataTypes/DataTypeDateTime.h>
|
|
|
|
#include <Core/Field.h>
|
|
|
|
|
|
|
|
|
|
|
|
namespace DB
|
|
|
|
{
|
|
|
|
struct Settings;
|
|
|
|
|
|
|
|
namespace ErrorCodes
|
|
|
|
{
|
|
|
|
extern const int ILLEGAL_TYPE_OF_ARGUMENT;
|
|
|
|
}
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
|
|
|
|
template <typename Value, bool _> using FuncQuantileTimingWeighted = AggregateFunctionQuantile<Value, QuantileTiming<Value>, NameQuantileTimingWeighted, true, Float32, false>;
|
|
|
|
template <typename Value, bool _> using FuncQuantilesTimingWeighted = AggregateFunctionQuantile<Value, QuantileTiming<Value>, NameQuantilesTimingWeighted, true, Float32, true>;
|
|
|
|
|
|
|
|
template <template <typename, bool> class Function>
|
|
|
|
AggregateFunctionPtr createAggregateFunctionQuantile(
|
|
|
|
const std::string & name, const DataTypes & argument_types, const Array & params, const Settings *)
|
|
|
|
{
|
|
|
|
/// Second argument type check doesn't depend on the type of the first one.
|
|
|
|
Function<void, true>::assertSecondArg(argument_types);
|
|
|
|
|
|
|
|
const DataTypePtr & argument_type = argument_types[0];
|
|
|
|
WhichDataType which(argument_type);
|
|
|
|
|
|
|
|
#define DISPATCH(TYPE) \
|
|
|
|
if (which.idx == TypeIndex::TYPE) return std::make_shared<Function<TYPE, true>>(argument_types, params);
|
|
|
|
FOR_BASIC_NUMERIC_TYPES(DISPATCH)
|
|
|
|
#undef DISPATCH
|
|
|
|
if (which.idx == TypeIndex::Date) return std::make_shared<Function<DataTypeDate::FieldType, false>>(argument_types, params);
|
|
|
|
if (which.idx == TypeIndex::DateTime) return std::make_shared<Function<DataTypeDateTime::FieldType, false>>(argument_types, params);
|
|
|
|
|
|
|
|
throw Exception("Illegal type " + argument_type->getName() + " of argument for aggregate function " + name,
|
|
|
|
ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2022-09-11 07:29:24 +00:00
|
|
|
void registerAggregateFunctionsQuantileTimingWeighted(AggregateFunctionFactory & factory)
|
2022-09-11 06:46:05 +00:00
|
|
|
{
|
|
|
|
/// For aggregate functions returning array we cannot return NULL on empty set.
|
|
|
|
AggregateFunctionProperties properties = { .returns_default_when_only_null = true };
|
|
|
|
|
|
|
|
factory.registerFunction(NameQuantileTimingWeighted::name, createAggregateFunctionQuantile<FuncQuantileTimingWeighted>);
|
|
|
|
factory.registerFunction(NameQuantilesTimingWeighted::name, { createAggregateFunctionQuantile<FuncQuantilesTimingWeighted>, properties });
|
|
|
|
|
|
|
|
/// 'median' is an alias for 'quantile'
|
|
|
|
factory.registerAlias("medianTimingWeighted", NameQuantileTimingWeighted::name);
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|