be/src/exprs/aggregate/aggregate_function_combinator.h
Line | Count | Source |
1 | | // Licensed to the Apache Software Foundation (ASF) under one |
2 | | // or more contributor license agreements. See the NOTICE file |
3 | | // distributed with this work for additional information |
4 | | // regarding copyright ownership. The ASF licenses this file |
5 | | // to you under the Apache License, Version 2.0 (the |
6 | | // "License"); you may not use this file except in compliance |
7 | | // with the License. You may obtain a copy of the License at |
8 | | // |
9 | | // http://www.apache.org/licenses/LICENSE-2.0 |
10 | | // |
11 | | // Unless required by applicable law or agreed to in writing, |
12 | | // software distributed under the License is distributed on an |
13 | | // "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY |
14 | | // KIND, either express or implied. See the License for the |
15 | | // specific language governing permissions and limitations |
16 | | // under the License. |
17 | | // This file is copied from |
18 | | // https://github.com/ClickHouse/ClickHouse/blob/master/src/AggregateFunctions/IAggregateFunctionCombinator.h |
19 | | // and modified by Doris |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include <memory> |
24 | | |
25 | | #include "core/data_type/data_type.h" |
26 | | #include "exprs/aggregate/aggregate_function.h" |
27 | | |
28 | | namespace doris { |
29 | | #include "common/compile_check_begin.h" |
30 | | |
31 | | /** Aggregate function combinator allows to take one aggregate function |
32 | | * and transform it to another aggregate function. |
33 | | * |
34 | | * In SQL language they are used as suffixes for existing aggregate functions. |
35 | | * |
36 | | * Example: -If combinator takes an aggregate function and transforms it |
37 | | * to aggregate function with additional argument at end (condition), |
38 | | * that will pass values to original aggregate function when the condition is true. |
39 | | * |
40 | | * More examples: |
41 | | * |
42 | | * sum(x) - calculate sum of x |
43 | | * sumIf(x, cond) - calculate sum of x for rows where condition is true. |
44 | | * sumArray(arr) - calculate sum of all elements of arrays. |
45 | | * |
46 | | * PS. Please don't mess it with so called "combiner" - totally unrelated notion from Hadoop world. |
47 | | * "combining" - merging the states of aggregate functions - is supported naturally in ClickHouse. |
48 | | */ |
49 | | |
50 | | class IAggregateFunctionCombinator { |
51 | | public: |
52 | | virtual String get_name() const = 0; |
53 | | |
54 | | /** From the arguments for combined function (ex: UInt64, UInt8 for sumIf), |
55 | | * get the arguments for nested function (ex: UInt64 for sum). |
56 | | * If arguments are not suitable for combined function, throw an exception. |
57 | | */ |
58 | 0 | virtual DataTypes transform_arguments(const DataTypes& arguments) const { return arguments; } |
59 | | |
60 | | /** Create combined aggregate function (ex: sumIf) |
61 | | * from nested function (ex: sum) |
62 | | * and arguments for combined aggregate function (ex: UInt64, UInt8 for sumIf). |
63 | | * It's assumed that function transform_arguments was called before this function and 'arguments' are validated. |
64 | | */ |
65 | | virtual AggregateFunctionPtr transform_aggregate_function( |
66 | | const AggregateFunctionPtr& nested_function, const DataTypes& arguments, |
67 | | const bool result_is_nullable, const AggregateFunctionAttr& attr) const = 0; |
68 | | |
69 | 0 | virtual ~IAggregateFunctionCombinator() = default; |
70 | | }; |
71 | | |
72 | | } // namespace doris |
73 | | |
74 | | #include "common/compile_check_end.h" |