ClickHouse

Форк
0
/
AggregateFunctionQuantileExactHigh.cpp 
68 строк · 3.1 Кб
1
#include <AggregateFunctions/AggregateFunctionQuantile.h>
2
#include <AggregateFunctions/QuantileExact.h>
3
#include <AggregateFunctions/AggregateFunctionFactory.h>
4
#include <AggregateFunctions/Helpers.h>
5
#include <DataTypes/DataTypeDate.h>
6
#include <DataTypes/DataTypeDateTime.h>
7
#include <Core/Field.h>
8

9

10
namespace DB
11
{
12
struct Settings;
13

14
namespace ErrorCodes
15
{
16
    extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
17
    extern const int ILLEGAL_TYPE_OF_ARGUMENT;
18
}
19

20
namespace
21
{
22

23
template <typename Value, bool _> using FuncQuantileExactHigh = AggregateFunctionQuantile<Value, QuantileExactHigh<Value>, NameQuantileExactHigh, false, void, false, false>;
24
template <typename Value, bool _> using FuncQuantilesExactHigh = AggregateFunctionQuantile<Value, QuantileExactHigh<Value>, NameQuantilesExactHigh, false, void, true, false>;
25

26

27
template <template <typename, bool> class Function>
28
AggregateFunctionPtr createAggregateFunctionQuantile(
29
    const std::string & name, const DataTypes & argument_types, const Array & params, const Settings *)
30
{
31
    if (argument_types.empty())
32
        throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH, "Aggregate function {} requires at least one argument", name);
33

34
    const DataTypePtr & argument_type = argument_types[0];
35
    WhichDataType which(argument_type);
36

37
#define DISPATCH(TYPE) \
38
    if (which.idx == TypeIndex::TYPE) return std::make_shared<Function<TYPE, true>>(argument_types, params);
39
    FOR_BASIC_NUMERIC_TYPES(DISPATCH)
40
#undef DISPATCH
41
    if (which.idx == TypeIndex::Date) return std::make_shared<Function<DataTypeDate::FieldType, false>>(argument_types, params);
42
    if (which.idx == TypeIndex::DateTime) return std::make_shared<Function<DataTypeDateTime::FieldType, false>>(argument_types, params);
43
    if (which.idx == TypeIndex::DateTime64) return std::make_shared<Function<DateTime64, false>>(argument_types, params);
44

45
    if (which.idx == TypeIndex::Decimal32) return std::make_shared<Function<Decimal32, false>>(argument_types, params);
46
    if (which.idx == TypeIndex::Decimal64) return std::make_shared<Function<Decimal64, false>>(argument_types, params);
47
    if (which.idx == TypeIndex::Decimal128) return std::make_shared<Function<Decimal128, false>>(argument_types, params);
48
    if (which.idx == TypeIndex::Decimal256) return std::make_shared<Function<Decimal256, false>>(argument_types, params);
49

50
    throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT, "Illegal type {} of argument for aggregate function {}",
51
                    argument_type->getName(), name);
52
}
53

54
}
55

56
void registerAggregateFunctionsQuantileExactHigh(AggregateFunctionFactory & factory)
57
{
58
    /// For aggregate functions returning array we cannot return NULL on empty set.
59
    AggregateFunctionProperties properties = { .returns_default_when_only_null = true };
60

61
    factory.registerFunction(NameQuantileExactHigh::name, createAggregateFunctionQuantile<FuncQuantileExactHigh>);
62
    factory.registerFunction(NameQuantilesExactHigh::name, { createAggregateFunctionQuantile<FuncQuantilesExactHigh>, properties });
63

64
    /// 'median' is an alias for 'quantile'
65
    factory.registerAlias("medianExactHigh", NameQuantileExactHigh::name);
66
}
67

68
}
69

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.