ClickHouse

Форк
0
/
AggregateFunctionResample.cpp 
100 строк · 3.1 Кб
1
#include "AggregateFunctionResample.h"
2
#include "AggregateFunctionCombinatorFactory.h"
3

4
namespace DB
5
{
6

7
namespace ErrorCodes
8
{
9
    extern const int ILLEGAL_TYPE_OF_ARGUMENT;
10
    extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
11
}
12

13
namespace
14
{
15

16
class AggregateFunctionCombinatorResample final : public IAggregateFunctionCombinator
17
{
18
public:
19
    String getName() const override
20
    {
21
        return "Resample";
22
    }
23

24
    DataTypes transformArguments(const DataTypes & arguments) const override
25
    {
26
        if (arguments.empty())
27
            throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH,
28
                    "Incorrect number of arguments for aggregate function with {} suffix", getName());
29

30
        return DataTypes(arguments.begin(), arguments.end() - 1);
31
    }
32

33
    Array transformParameters(const Array & params) const override
34
    {
35
        if (params.size() < 3)
36
            throw Exception(ErrorCodes::NUMBER_OF_ARGUMENTS_DOESNT_MATCH,
37
                    "Incorrect number of parameters for aggregate function with {} suffix", getName());
38

39
        return Array(params.begin(), params.end() - 3);
40
    }
41

42
    AggregateFunctionPtr transformAggregateFunction(
43
        const AggregateFunctionPtr & nested_function,
44
        const AggregateFunctionProperties &,
45
        const DataTypes & arguments,
46
        const Array & params) const override
47
    {
48
        WhichDataType which{arguments.back()};
49

50
        if (which.isNativeUInt() || which.isDate() || which.isDateTime() || which.isDateTime64())
51
        {
52
            UInt64 begin = params[params.size() - 3].safeGet<UInt64>();
53
            UInt64 end = params[params.size() - 2].safeGet<UInt64>();
54

55
            UInt64 step = params[params.size() - 1].safeGet<UInt64>();
56

57
            return std::make_shared<AggregateFunctionResample<UInt64>>(
58
                nested_function,
59
                begin,
60
                end,
61
                step,
62
                arguments,
63
                params);
64
        }
65

66
        if (which.isNativeInt() || which.isEnum() || which.isInterval())
67
        {
68
            Int64 begin, end;
69

70
            // notice: UInt64 -> Int64 may lead to overflow
71
            if (!params[params.size() - 3].tryGet<Int64>(begin))
72
                begin = params[params.size() - 3].safeGet<UInt64>();
73
            if (!params[params.size() - 2].tryGet<Int64>(end))
74
                end = params[params.size() - 2].safeGet<UInt64>();
75

76
            UInt64 step = params[params.size() - 1].safeGet<UInt64>();
77

78
            return std::make_shared<AggregateFunctionResample<Int64>>(
79
                nested_function,
80
                begin,
81
                end,
82
                step,
83
                arguments,
84
                params);
85
        }
86

87
        throw Exception(ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
88
                        "Illegal types of argument for aggregate function {}, the type "
89
                        "of the last argument should be native integer or integer-like", getName());
90
    }
91
};
92

93
}
94

95
void registerAggregateFunctionCombinatorResample(AggregateFunctionCombinatorFactory & factory)
96
{
97
    factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorResample>());
98
}
99

100
}
101

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

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

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

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