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/AggregateFunctionWindowFunnel.cpp | |
| parent | d4ae8f119e67808cb0cf776ba6e0cf95296f2df7 (diff) | |
YQ Connector: move tests from yql to ydb (OSS)
Перенос папки с тестами на Коннектор из папки yql в папку ydb (синхронизируется с github).
Diffstat (limited to 'contrib/clickhouse/src/AggregateFunctions/AggregateFunctionWindowFunnel.cpp')
| -rw-r--r-- | contrib/clickhouse/src/AggregateFunctions/AggregateFunctionWindowFunnel.cpp | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/contrib/clickhouse/src/AggregateFunctions/AggregateFunctionWindowFunnel.cpp b/contrib/clickhouse/src/AggregateFunctions/AggregateFunctionWindowFunnel.cpp new file mode 100644 index 00000000000..d80d683fd04 --- /dev/null +++ b/contrib/clickhouse/src/AggregateFunctions/AggregateFunctionWindowFunnel.cpp @@ -0,0 +1,72 @@ +#include <AggregateFunctions/AggregateFunctionFactory.h> +#include <AggregateFunctions/AggregateFunctionWindowFunnel.h> +#include <AggregateFunctions/FactoryHelpers.h> +#include <AggregateFunctions/Helpers.h> +#include <Core/Settings.h> +#include <DataTypes/DataTypeDate.h> +#include <DataTypes/DataTypeDate32.h> +#include <DataTypes/DataTypeDateTime.h> + +#include <base/range.h> + + +namespace DB +{ +struct Settings; + +namespace ErrorCodes +{ + extern const int ILLEGAL_TYPE_OF_ARGUMENT; + extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH; +} + +namespace +{ + +template <template <typename> class Data> +AggregateFunctionPtr +createAggregateFunctionWindowFunnel(const std::string & name, const DataTypes & arguments, const Array & params, const Settings *) +{ + if (params.empty()) + throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, + "Aggregate function {} requires at least one parameter: <window>, [option, [option, ...]]", + name); + + if (arguments.size() < 2) + throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, + "Aggregate function {} requires one timestamp argument and at least one event condition.", name); + + if (arguments.size() > max_events + 1) + throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Too many event arguments for aggregate function {}", name); + + for (const auto i : collections::range(1, arguments.size())) + { + const auto * cond_arg = arguments[i].get(); + if (!isUInt8(cond_arg)) + throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of argument {} of aggregate function {}, must be UInt8", + cond_arg->getName(), toString(i + 1), name); + } + + AggregateFunctionPtr res(createWithUnsignedIntegerType<AggregateFunctionWindowFunnel, Data>(*arguments[0], arguments, params)); + WhichDataType which(arguments.front().get()); + if (res) + return res; + else if (which.isDate()) + return std::make_shared<AggregateFunctionWindowFunnel<DataTypeDate::FieldType, Data<DataTypeDate::FieldType>>>(arguments, params); + else if (which.isDateTime()) + return std::make_shared<AggregateFunctionWindowFunnel<DataTypeDateTime::FieldType, Data<DataTypeDateTime::FieldType>>>(arguments, params); + + throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, + "Illegal type {} of first argument of aggregate function {}, must " + "be Unsigned Number, Date, DateTime", arguments.front().get()->getName(), name); +} + +} + +void registerAggregateFunctionWindowFunnel(AggregateFunctionFactory & factory) +{ + factory.registerFunction("windowFunnel", createAggregateFunctionWindowFunnel<AggregateFunctionWindowFunnelData>); +} + +} |
