Coverage Report

Created: 2026-03-15 01:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_binary.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
18
#pragma once
19
20
#include <glog/logging.h>
21
22
#include <cmath>
23
24
#include "core/column/column_decimal.h"
25
#include "core/column/column_vector.h"
26
#include "core/data_type/data_type_decimal.h"
27
#include "core/data_type/data_type_nullable.h"
28
#include "core/data_type/data_type_number.h"
29
#include "core/string_buffer.hpp"
30
#include "core/types.h"
31
#include "exprs/aggregate/aggregate_function.h"
32
33
namespace doris {
34
#include "common/compile_check_begin.h"
35
36
template <PrimitiveType T, template <PrimitiveType> typename Moments>
37
struct StatFunc {
38
    using ColVecT1 = typename PrimitiveTypeTraits<T>::ColumnType;
39
    using ColVecT2 = ColVecT1;
40
    using Data = Moments<TYPE_DOUBLE>;
41
    static constexpr PrimitiveType ResultPrimitiveType = TYPE_DOUBLE;
42
};
43
44
template <typename StatFunc>
45
struct AggregateFunctionBinary
46
        : public IAggregateFunctionDataHelper<typename StatFunc::Data,
47
                                              AggregateFunctionBinary<StatFunc>>,
48
          MultiExpression,
49
          NullableAggregateFunction {
50
    static constexpr PrimitiveType ResultType = StatFunc::ResultPrimitiveType;
51
52
    using ColVecT1 = typename StatFunc::ColVecT1;
53
    using ColVecT2 = typename StatFunc::ColVecT2;
54
    using ColVecResult = ColumnVector<ResultType>;
55
    static constexpr UInt32 num_args = 2;
56
57
    AggregateFunctionBinary(const DataTypes& argument_types_)
58
2
            : IAggregateFunctionDataHelper<typename StatFunc::Data,
59
2
                                           AggregateFunctionBinary<StatFunc>>(argument_types_) {}
_ZN5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaISA_EE
Line
Count
Source
58
1
            : IAggregateFunctionDataHelper<typename StatFunc::Data,
59
1
                                           AggregateFunctionBinary<StatFunc>>(argument_types_) {}
_ZN5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaISA_EE
Line
Count
Source
58
1
            : IAggregateFunctionDataHelper<typename StatFunc::Data,
59
1
                                           AggregateFunctionBinary<StatFunc>>(argument_types_) {}
60
61
2
    String get_name() const override { return StatFunc::Data::name(); }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE8get_nameB5cxx11Ev
Line
Count
Source
61
1
    String get_name() const override { return StatFunc::Data::name(); }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE8get_nameB5cxx11Ev
Line
Count
Source
61
1
    String get_name() const override { return StatFunc::Data::name(); }
62
63
2
    void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE5resetEPc
Line
Count
Source
63
1
    void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE5resetEPc
Line
Count
Source
63
1
    void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }
64
65
2
    DataTypePtr get_return_type() const override {
66
2
        return std::make_shared<DataTypeNumber<StatFunc::ResultPrimitiveType>>();
67
2
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE15get_return_typeEv
Line
Count
Source
65
1
    DataTypePtr get_return_type() const override {
66
1
        return std::make_shared<DataTypeNumber<StatFunc::ResultPrimitiveType>>();
67
1
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE15get_return_typeEv
Line
Count
Source
65
1
    DataTypePtr get_return_type() const override {
66
1
        return std::make_shared<DataTypeNumber<StatFunc::ResultPrimitiveType>>();
67
1
    }
68
69
    void add(AggregateDataPtr __restrict place, const IColumn** columns, ssize_t row_num,
70
70
             Arena&) const override {
71
70
        this->data(place).add(
72
70
                static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>(
73
70
                        static_cast<const ColVecT1&>(*columns[0]).get_data()[row_num]),
74
70
                static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>(
75
70
                        static_cast<const ColVecT2&>(*columns[1]).get_data()[row_num]));
76
70
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Line
Count
Source
70
35
             Arena&) const override {
71
35
        this->data(place).add(
72
35
                static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>(
73
35
                        static_cast<const ColVecT1&>(*columns[0]).get_data()[row_num]),
74
35
                static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>(
75
35
                        static_cast<const ColVecT2&>(*columns[1]).get_data()[row_num]));
76
35
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Line
Count
Source
70
35
             Arena&) const override {
71
35
        this->data(place).add(
72
35
                static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>(
73
35
                        static_cast<const ColVecT1&>(*columns[0]).get_data()[row_num]),
74
35
                static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>(
75
35
                        static_cast<const ColVecT2&>(*columns[1]).get_data()[row_num]));
76
35
    }
77
78
    void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs,
79
16
               Arena&) const override {
80
16
        this->data(place).merge(this->data(rhs));
81
16
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE5mergeEPcPKcRNS_5ArenaE
Line
Count
Source
79
8
               Arena&) const override {
80
8
        this->data(place).merge(this->data(rhs));
81
8
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE5mergeEPcPKcRNS_5ArenaE
Line
Count
Source
79
8
               Arena&) const override {
80
8
        this->data(place).merge(this->data(rhs));
81
8
    }
82
83
18
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
84
18
        this->data(place).write(buf);
85
18
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE9serializeEPKcRNS_14BufferWritableE
Line
Count
Source
83
9
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
84
9
        this->data(place).write(buf);
85
9
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE9serializeEPKcRNS_14BufferWritableE
Line
Count
Source
83
9
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
84
9
        this->data(place).write(buf);
85
9
    }
86
87
    void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf,
88
16
                     Arena&) const override {
89
16
        this->data(place).read(buf);
90
16
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Line
Count
Source
88
8
                     Arena&) const override {
89
8
        this->data(place).read(buf);
90
8
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Line
Count
Source
88
8
                     Arena&) const override {
89
8
        this->data(place).read(buf);
90
8
    }
91
92
12
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
93
12
        const auto& data = this->data(place);
94
12
        auto& dst = static_cast<ColVecResult&>(to).get_data();
95
12
        dst.push_back(data.get());
96
12
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE18insert_result_intoEPKcRNS_7IColumnE
Line
Count
Source
92
6
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
93
6
        const auto& data = this->data(place);
94
6
        auto& dst = static_cast<ColVecResult&>(to).get_data();
95
6
        dst.push_back(data.get());
96
6
    }
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE18insert_result_intoEPKcRNS_7IColumnE
Line
Count
Source
92
6
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
93
6
        const auto& data = this->data(place);
94
6
        auto& dst = static_cast<ColVecResult&>(to).get_data();
95
6
        dst.push_back(data.get());
96
6
    }
97
};
98
99
} // namespace doris
100
101
#include "common/compile_check_end.h"