aboutsummaryrefslogtreecommitdiffstats
path: root/contrib/clickhouse/src/AggregateFunctions/IAggregateFunction.cpp
blob: 7da341cc5b9956ef7c0d194f9c791879d371aa45 (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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
#include <AggregateFunctions/IAggregateFunction.h>
#include <DataTypes/DataTypeAggregateFunction.h>


namespace DB
{

DataTypePtr IAggregateFunction::getStateType() const
{
    return std::make_shared<DataTypeAggregateFunction>(shared_from_this(), argument_types, parameters);
}

String IAggregateFunction::getDescription() const
{
    String description;

    description += getName();

    description += '(';

    for (const auto & parameter : parameters)
    {
        description += parameter.dump();
        description += ", ";
    }

    if (!parameters.empty())
    {
        description.pop_back();
        description.pop_back();
    }

    description += ')';

    description += '(';

    for (const auto & argument_type : argument_types)
    {
        description += argument_type->getName();
        description += ", ";
    }

    if (!argument_types.empty())
    {
        description.pop_back();
        description.pop_back();
    }

    description += ')';

    return description;
}

bool IAggregateFunction::haveEqualArgumentTypes(const IAggregateFunction & rhs) const
{
    return std::equal(
        argument_types.begin(),
        argument_types.end(),
        rhs.argument_types.begin(),
        rhs.argument_types.end(),
        [](const auto & t1, const auto & t2) { return t1->equals(*t2); });
}

bool IAggregateFunction::haveSameStateRepresentation(const IAggregateFunction & rhs) const
{
    const auto & lhs_base = getBaseAggregateFunctionWithSameStateRepresentation();
    const auto & rhs_base = rhs.getBaseAggregateFunctionWithSameStateRepresentation();
    return lhs_base.haveSameStateRepresentationImpl(rhs_base);
}

bool IAggregateFunction::haveSameStateRepresentationImpl(const IAggregateFunction & rhs) const
{
    return getStateType()->equals(*rhs.getStateType());
}

}