Coverage Report

Created: 2026-04-15 19:01

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
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
30
/** Aggregate function combinator allows to take one aggregate function
31
  *  and transform it to another aggregate function.
32
  *
33
  * In SQL language they are used as suffixes for existing aggregate functions.
34
  *
35
  * Example: -If combinator takes an aggregate function and transforms it
36
  *  to aggregate function with additional argument at end (condition),
37
  *  that will pass values to original aggregate function when the condition is true.
38
  *
39
  * More examples:
40
  *
41
  * sum(x) - calculate sum of x
42
  * sumIf(x, cond) - calculate sum of x for rows where condition is true.
43
  * sumArray(arr) - calculate sum of all elements of arrays.
44
  *
45
  * PS. Please don't mess it with so called "combiner" - totally unrelated notion from Hadoop world.
46
  * "combining" - merging the states of aggregate functions - is supported naturally in ClickHouse.
47
  */
48
49
class IAggregateFunctionCombinator {
50
public:
51
    virtual String get_name() const = 0;
52
53
    /** From the arguments for combined function (ex: UInt64, UInt8 for sumIf),
54
      *  get the arguments for nested function (ex: UInt64 for sum).
55
      * If arguments are not suitable for combined function, throw an exception.
56
      */
57
0
    virtual DataTypes transform_arguments(const DataTypes& arguments) const { return arguments; }
58
59
    /** Create combined aggregate function (ex: sumIf)
60
      *  from nested function (ex: sum)
61
      *  and arguments for combined aggregate function (ex: UInt64, UInt8 for sumIf).
62
      * It's assumed that function transform_arguments was called before this function and 'arguments' are validated.
63
      */
64
    virtual AggregateFunctionPtr transform_aggregate_function(
65
            const AggregateFunctionPtr& nested_function, const DataTypes& arguments,
66
            const bool result_is_nullable, const AggregateFunctionAttr& attr) const = 0;
67
68
0
    virtual ~IAggregateFunctionCombinator() = default;
69
};
70
71
} // namespace doris