aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/AggregateFunctions/AggregateFunctionOrFill.cpp
blob: 7aee02898796d6859ca3f12cd2a555e923696c75 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#include <AggregateFunctions/AggregateFunctionOrFill.h>

#include <AggregateFunctions/AggregateFunctionCombinatorFactory.h>


namespace DB
{

namespace
{

enum class Kind
{
    OrNull,
    OrDefault
};

class AggregateFunctionCombinatorOrFill final : public IAggregateFunctionCombinator
{
private:
    Kind kind;

public:
    explicit AggregateFunctionCombinatorOrFill(Kind kind_) : kind(kind_) {}

    /// Due to aggregate_functions_null_for_empty
    bool supportsNesting() const override { return true; }

    String getName() const override
    {
        return kind == Kind::OrNull ? "OrNull" : "OrDefault";
    }

    AggregateFunctionPtr transformAggregateFunction(
        const AggregateFunctionPtr & nested_function,
        const AggregateFunctionProperties &,
        const DataTypes & arguments,
        const Array & params) const override
    {
        if (kind == Kind::OrNull)
            return std::make_shared<AggregateFunctionOrFill<true>>(nested_function, arguments, params);
        else
            return std::make_shared<AggregateFunctionOrFill<false>>(nested_function, arguments, params);
    }
};

}

void registerAggregateFunctionCombinatorOrFill(AggregateFunctionCombinatorFactory & factory)
{
    factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorOrFill>(Kind::OrNull));
    factory.registerCombinator(std::make_shared<AggregateFunctionCombinatorOrFill>(Kind::OrDefault));
}

}