diff options
| author | vitalyisaev <[email protected]> | 2023-11-14 09:58:56 +0300 |
|---|---|---|
| committer | vitalyisaev <[email protected]> | 2023-11-14 10:20:20 +0300 |
| commit | c2b2dfd9827a400a8495e172a56343462e3ceb82 (patch) | |
| tree | cd4e4f597d01bede4c82dffeb2d780d0a9046bd0 /contrib/clickhouse/src/AggregateFunctions/AggregateFunctionQuantileApprox.cpp | |
| parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/AggregateFunctions/AggregateFunctionQuantileApprox.cpp')
| -rw-r--r-- | contrib/clickhouse/src/AggregateFunctions/AggregateFunctionQuantileApprox.cpp | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/AggregateFunctions/AggregateFunctionQuantileApprox.cpp b/contrib/clickhouse/src/AggregateFunctions/AggregateFunctionQuantileApprox.cpp new file mode 100644 index 00000000000..c190aaa30d5 --- /dev/null +++ b/contrib/clickhouse/src/AggregateFunctions/AggregateFunctionQuantileApprox.cpp @@ -0,0 +1,71 @@ +#include <AggregateFunctions/AggregateFunctionQuantile.h> +#include <AggregateFunctions/QuantileApprox.h> +#include <AggregateFunctions/AggregateFunctionFactory.h> +#include <AggregateFunctions/Helpers.h> +#include <DataTypes/DataTypeDate.h> +#include <DataTypes/DataTypeDateTime.h> +#include <Core/Field.h> + +namespace DB +{ + +namespace ErrorCodes +{ + extern const int ILLEGAL_TYPE_OF_ARGUMENT; +} + +namespace +{ + +template <typename Value, bool _> using FuncQuantileGK = AggregateFunctionQuantile<Value, QuantileGK<Value>, NameQuantileGK, false, void, false>; +template <typename Value, bool _> using FuncQuantilesGK = AggregateFunctionQuantile<Value, QuantileGK<Value>, NameQuantilesGK, false, void, 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); + + if (which.idx == TypeIndex::Decimal32) return std::make_shared<Function<Decimal32, false>>(argument_types, params); + if (which.idx == TypeIndex::Decimal64) return std::make_shared<Function<Decimal64, false>>(argument_types, params); + if (which.idx == TypeIndex::Decimal128) return std::make_shared<Function<Decimal128, false>>(argument_types, params); + if (which.idx == TypeIndex::Decimal256) return std::make_shared<Function<Decimal256, false>>(argument_types, params); + if (which.idx == TypeIndex::DateTime64) return std::make_shared<Function<DateTime64, false>>(argument_types, params); + + if (which.idx == TypeIndex::Int128) return std::make_shared<Function<Int128, true>>(argument_types, params); + if (which.idx == TypeIndex::UInt128) return std::make_shared<Function<UInt128, true>>(argument_types, params); + if (which.idx == TypeIndex::Int256) return std::make_shared<Function<Int256, true>>(argument_types, params); + if (which.idx == TypeIndex::UInt256) return std::make_shared<Function<UInt256, true>>(argument_types, params); + + throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of argument for aggregate function {}", + argument_type->getName(), name); +} + +} + +void registerAggregateFunctionsQuantileApprox(AggregateFunctionFactory & factory) +{ + /// For aggregate functions returning array we cannot return NULL on empty set. + AggregateFunctionProperties properties = { .returns_default_when_only_null = true }; + + factory.registerFunction(NameQuantileGK::name, createAggregateFunctionQuantile<FuncQuantileGK>); + factory.registerFunction(NameQuantilesGK::name, {createAggregateFunctionQuantile<FuncQuantilesGK>, properties}); + + /// 'median' is an alias for 'quantile' + factory.registerAlias("medianGK", NameQuantileGK::name); +} + +} |
