ClickHouse

Форк
0
/
AggregateFunctionMerge.cpp 
81 строка · 2.7 Кб
1
#include "AggregateFunctionMerge.h"
2
#include "AggregateFunctionCombinatorFactory.h"
3

4
#include <DataTypes/DataTypeAggregateFunction.h>
5

6
namespace DB
7
{
8

9
namespace ErrorCodes
10
{
11
    extern const int ILLEGAL_TYPE_OF_ARGUMENT;
12
    extern const int NUMBER_OF_ARGUMENTS_DOESNT_MATCH;
13
}
14

15
namespace
16
{
17

18
class AggregateFunctionCombinatorMerge final : public IAggregateFunctionCombinator
19
{
20
public:
21
    String getName() const override { return "Merge"; }
22

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

31
        const DataTypePtr & argument = arguments[0];
32

33
        const DataTypeAggregateFunction * function = typeid_cast<const DataTypeAggregateFunction *>(argument.get());
34
        if (!function)
35
            throw Exception(
36
                ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
37
                "Illegal type {} of argument for aggregate function with {} suffix. It must be AggregateFunction(...)",
38
                argument->getName(),
39
                getName());
40

41
        return function->getArgumentsDataTypes();
42
    }
43

44
    AggregateFunctionPtr transformAggregateFunction(
45
        const AggregateFunctionPtr & nested_function,
46
        const AggregateFunctionProperties &,
47
        const DataTypes & arguments,
48
        const Array & params) const override
49
    {
50
        const DataTypePtr & argument = arguments[0];
51

52
        const DataTypeAggregateFunction * function = typeid_cast<const DataTypeAggregateFunction *>(argument.get());
53
        if (!function)
54
            throw Exception(
55
                ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
56
                "Illegal type {} of argument for aggregate function with {} suffix. It must be AggregateFunction(...)",
57
                argument->getName(),
58
                getName());
59

60
        if (!nested_function->haveSameStateRepresentation(*function->getFunction()))
61
            throw Exception(
62
                ErrorCodes::ILLEGAL_TYPE_OF_ARGUMENT,
63
                "Illegal type {} of argument for aggregate function with {} suffix. because it corresponds to different aggregate "
64
                "function: {} instead of {}",
65
                argument->getName(),
66
                getName(),
67
                function->getFunctionName(),
68
                nested_function->getName());
69

70
        return std::make_shared<AggregateFunctionMerge>(nested_function, argument, params);
71
    }
72
};
73

74
}
75

76
void registerAggregateFunctionCombinatorMerge(AggregateFunctionCombinatorFactory & factory)
77
{
78
    factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorMerge>());
79
}
80

81
}
82

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

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

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

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