Coverage Report

Created: 2026-04-14 10:14

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/aggregate/aggregate_function_statistic.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
#include <cmath>
20
#include <cstdint>
21
#include <string>
22
23
#include "common/exception.h"
24
#include "common/status.h"
25
#include "core/assert_cast.h"
26
#include "core/column/column_nullable.h"
27
#include "core/column/column_vector.h"
28
#include "core/data_type/data_type.h"
29
#include "core/data_type/data_type_nullable.h"
30
#include "core/data_type/data_type_number.h"
31
#include "core/types.h"
32
#include "exprs/aggregate/aggregate_function.h"
33
#include "exprs/aggregate/moments.h"
34
35
namespace doris {
36
37
enum class STATISTICS_FUNCTION_KIND : uint8_t { SKEW_POP, KURT_POP };
38
39
0
inline std::string to_string(STATISTICS_FUNCTION_KIND kind) {
40
0
    switch (kind) {
41
0
    case STATISTICS_FUNCTION_KIND::SKEW_POP:
42
0
        return "skewness";
43
0
    case STATISTICS_FUNCTION_KIND::KURT_POP:
44
0
        return "kurtosis";
45
0
    default:
46
0
        return "Unknown";
47
0
    }
48
0
}
49
50
template <PrimitiveType T, std::size_t _level>
51
struct StatFuncOneArg {
52
    static constexpr PrimitiveType Type = T;
53
    using Data = VarMoments<Float64, _level>;
54
    using DataType = Float64;
55
};
56
57
template <typename StatFunc, bool NullableInput>
58
class AggregateFunctionVarianceSimple
59
        : public IAggregateFunctionDataHelper<
60
                  typename StatFunc::Data,
61
                  AggregateFunctionVarianceSimple<StatFunc, NullableInput>> {
62
public:
63
    using InputCol = ColumnVector<StatFunc::Type>;
64
    using ResultCol = ColumnFloat64;
65
    using InputType = typename StatFunc::DataType;
66
67
    explicit AggregateFunctionVarianceSimple(STATISTICS_FUNCTION_KIND kind_,
68
                                             const DataTypes& argument_types_)
69
52
            : IAggregateFunctionDataHelper<
70
52
                      typename StatFunc::Data,
71
52
                      AggregateFunctionVarianceSimple<StatFunc, NullableInput>>(argument_types_),
72
52
              kind(kind_) {
73
52
        DCHECK(!argument_types_.empty());
74
52
    }
_ZN5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb1EEC2ENS_24STATISTICS_FUNCTION_KINDERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaISA_EE
Line
Count
Source
69
13
            : IAggregateFunctionDataHelper<
70
13
                      typename StatFunc::Data,
71
13
                      AggregateFunctionVarianceSimple<StatFunc, NullableInput>>(argument_types_),
72
13
              kind(kind_) {
73
        DCHECK(!argument_types_.empty());
74
13
    }
_ZN5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb0EEC2ENS_24STATISTICS_FUNCTION_KINDERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaISA_EE
Line
Count
Source
69
13
            : IAggregateFunctionDataHelper<
70
13
                      typename StatFunc::Data,
71
13
                      AggregateFunctionVarianceSimple<StatFunc, NullableInput>>(argument_types_),
72
13
              kind(kind_) {
73
        DCHECK(!argument_types_.empty());
74
13
    }
_ZN5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb1EEC2ENS_24STATISTICS_FUNCTION_KINDERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaISA_EE
Line
Count
Source
69
13
            : IAggregateFunctionDataHelper<
70
13
                      typename StatFunc::Data,
71
13
                      AggregateFunctionVarianceSimple<StatFunc, NullableInput>>(argument_types_),
72
13
              kind(kind_) {
73
        DCHECK(!argument_types_.empty());
74
13
    }
_ZN5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb0EEC2ENS_24STATISTICS_FUNCTION_KINDERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaISA_EE
Line
Count
Source
69
13
            : IAggregateFunctionDataHelper<
70
13
                      typename StatFunc::Data,
71
13
                      AggregateFunctionVarianceSimple<StatFunc, NullableInput>>(argument_types_),
72
13
              kind(kind_) {
73
        DCHECK(!argument_types_.empty());
74
13
    }
75
76
0
    String get_name() const override { return to_string(kind); }
Unexecuted instantiation: _ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb1EE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb0EE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb1EE8get_nameB5cxx11Ev
Unexecuted instantiation: _ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb0EE8get_nameB5cxx11Ev
77
78
108
    DataTypePtr get_return_type() const override {
79
108
        return make_nullable(std::make_shared<DataTypeFloat64>());
80
108
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb1EE15get_return_typeEv
Line
Count
Source
78
27
    DataTypePtr get_return_type() const override {
79
27
        return make_nullable(std::make_shared<DataTypeFloat64>());
80
27
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb0EE15get_return_typeEv
Line
Count
Source
78
27
    DataTypePtr get_return_type() const override {
79
27
        return make_nullable(std::make_shared<DataTypeFloat64>());
80
27
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb1EE15get_return_typeEv
Line
Count
Source
78
27
    DataTypePtr get_return_type() const override {
79
27
        return make_nullable(std::make_shared<DataTypeFloat64>());
80
27
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb0EE15get_return_typeEv
Line
Count
Source
78
27
    DataTypePtr get_return_type() const override {
79
27
        return make_nullable(std::make_shared<DataTypeFloat64>());
80
27
    }
81
82
    void add(AggregateDataPtr __restrict place, const IColumn** columns, ssize_t row_num,
83
164
             Arena&) const override {
84
164
        if constexpr (NullableInput) {
85
82
            const ColumnNullable& column_with_nullable =
86
82
                    assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*columns[0]);
87
88
82
            if (column_with_nullable.is_null_at(row_num)) {
89
30
                return;
90
52
            } else {
91
52
                this->data(place).add(
92
52
                        (InputType)assert_cast<const InputCol&, TypeCheckOnRelease::DISABLE>(
93
52
                                column_with_nullable.get_nested_column())
94
52
                                .get_data()[row_num]);
95
52
            }
96
97
82
        } else {
98
82
            this->data(place).add(
99
82
                    (InputType)assert_cast<const InputCol&, TypeCheckOnRelease::DISABLE>(
100
82
                            *columns[0])
101
82
                            .get_data()[row_num]);
102
82
        }
103
164
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb1EE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Line
Count
Source
83
41
             Arena&) const override {
84
41
        if constexpr (NullableInput) {
85
41
            const ColumnNullable& column_with_nullable =
86
41
                    assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*columns[0]);
87
88
41
            if (column_with_nullable.is_null_at(row_num)) {
89
15
                return;
90
26
            } else {
91
26
                this->data(place).add(
92
26
                        (InputType)assert_cast<const InputCol&, TypeCheckOnRelease::DISABLE>(
93
26
                                column_with_nullable.get_nested_column())
94
26
                                .get_data()[row_num]);
95
26
            }
96
97
        } else {
98
            this->data(place).add(
99
                    (InputType)assert_cast<const InputCol&, TypeCheckOnRelease::DISABLE>(
100
                            *columns[0])
101
                            .get_data()[row_num]);
102
        }
103
41
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb0EE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Line
Count
Source
83
41
             Arena&) const override {
84
        if constexpr (NullableInput) {
85
            const ColumnNullable& column_with_nullable =
86
                    assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*columns[0]);
87
88
            if (column_with_nullable.is_null_at(row_num)) {
89
                return;
90
            } else {
91
                this->data(place).add(
92
                        (InputType)assert_cast<const InputCol&, TypeCheckOnRelease::DISABLE>(
93
                                column_with_nullable.get_nested_column())
94
                                .get_data()[row_num]);
95
            }
96
97
41
        } else {
98
41
            this->data(place).add(
99
41
                    (InputType)assert_cast<const InputCol&, TypeCheckOnRelease::DISABLE>(
100
41
                            *columns[0])
101
41
                            .get_data()[row_num]);
102
41
        }
103
41
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb1EE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Line
Count
Source
83
41
             Arena&) const override {
84
41
        if constexpr (NullableInput) {
85
41
            const ColumnNullable& column_with_nullable =
86
41
                    assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*columns[0]);
87
88
41
            if (column_with_nullable.is_null_at(row_num)) {
89
15
                return;
90
26
            } else {
91
26
                this->data(place).add(
92
26
                        (InputType)assert_cast<const InputCol&, TypeCheckOnRelease::DISABLE>(
93
26
                                column_with_nullable.get_nested_column())
94
26
                                .get_data()[row_num]);
95
26
            }
96
97
        } else {
98
            this->data(place).add(
99
                    (InputType)assert_cast<const InputCol&, TypeCheckOnRelease::DISABLE>(
100
                            *columns[0])
101
                            .get_data()[row_num]);
102
        }
103
41
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb0EE3addEPcPPKNS_7IColumnElRNS_5ArenaE
Line
Count
Source
83
41
             Arena&) const override {
84
        if constexpr (NullableInput) {
85
            const ColumnNullable& column_with_nullable =
86
                    assert_cast<const ColumnNullable&, TypeCheckOnRelease::DISABLE>(*columns[0]);
87
88
            if (column_with_nullable.is_null_at(row_num)) {
89
                return;
90
            } else {
91
                this->data(place).add(
92
                        (InputType)assert_cast<const InputCol&, TypeCheckOnRelease::DISABLE>(
93
                                column_with_nullable.get_nested_column())
94
                                .get_data()[row_num]);
95
            }
96
97
41
        } else {
98
41
            this->data(place).add(
99
41
                    (InputType)assert_cast<const InputCol&, TypeCheckOnRelease::DISABLE>(
100
41
                            *columns[0])
101
41
                            .get_data()[row_num]);
102
41
        }
103
41
    }
104
105
    void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs,
106
38
               Arena&) const override {
107
38
        this->data(place).merge(this->data(rhs));
108
38
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb1EE5mergeEPcPKcRNS_5ArenaE
Line
Count
Source
106
10
               Arena&) const override {
107
10
        this->data(place).merge(this->data(rhs));
108
10
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb0EE5mergeEPcPKcRNS_5ArenaE
Line
Count
Source
106
9
               Arena&) const override {
107
9
        this->data(place).merge(this->data(rhs));
108
9
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb1EE5mergeEPcPKcRNS_5ArenaE
Line
Count
Source
106
9
               Arena&) const override {
107
9
        this->data(place).merge(this->data(rhs));
108
9
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb0EE5mergeEPcPKcRNS_5ArenaE
Line
Count
Source
106
10
               Arena&) const override {
107
10
        this->data(place).merge(this->data(rhs));
108
10
    }
109
110
38
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
111
38
        this->data(place).write(buf);
112
38
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb1EE9serializeEPKcRNS_14BufferWritableE
Line
Count
Source
110
10
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
111
10
        this->data(place).write(buf);
112
10
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb0EE9serializeEPKcRNS_14BufferWritableE
Line
Count
Source
110
9
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
111
9
        this->data(place).write(buf);
112
9
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb1EE9serializeEPKcRNS_14BufferWritableE
Line
Count
Source
110
9
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
111
9
        this->data(place).write(buf);
112
9
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb0EE9serializeEPKcRNS_14BufferWritableE
Line
Count
Source
110
10
    void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override {
111
10
        this->data(place).write(buf);
112
10
    }
113
114
    void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf,
115
38
                     Arena&) const override {
116
38
        this->data(place).read(buf);
117
38
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb1EE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Line
Count
Source
115
10
                     Arena&) const override {
116
10
        this->data(place).read(buf);
117
10
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb0EE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Line
Count
Source
115
9
                     Arena&) const override {
116
9
        this->data(place).read(buf);
117
9
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb1EE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Line
Count
Source
115
9
                     Arena&) const override {
116
9
        this->data(place).read(buf);
117
9
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb0EE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE
Line
Count
Source
115
10
                     Arena&) const override {
116
10
        this->data(place).read(buf);
117
10
    }
118
119
84
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
120
84
        const auto& data = this->data(place);
121
84
        ColumnNullable& dst_column_with_nullable = assert_cast<ColumnNullable&>(to);
122
84
        ResultCol* dst_column =
123
84
                assert_cast<ResultCol*>(&(dst_column_with_nullable.get_nested_column()));
124
125
84
        switch (kind) {
126
42
        case STATISTICS_FUNCTION_KIND::SKEW_POP: {
127
            // If input is empty set, we will get NAN from get_population()
128
42
            Float64 var_value = data.get_population();
129
42
            Float64 moments_3 = data.get_moment_3();
130
131
42
            if (std::isnan(var_value) || std::isnan(moments_3) || var_value <= 0) {
132
36
                dst_column_with_nullable.get_null_map_data().push_back(1);
133
36
                dst_column->insert_default();
134
36
            } else {
135
6
                dst_column_with_nullable.get_null_map_data().push_back(0);
136
6
                dst_column->get_data().push_back(
137
6
                        static_cast<Float64>(moments_3 / pow(var_value, 1.5)));
138
6
            }
139
42
            break;
140
0
        }
141
42
        case STATISTICS_FUNCTION_KIND::KURT_POP: {
142
42
            Float64 var_value = data.get_population();
143
42
            Float64 moments_4 = data.get_moment_4();
144
145
42
            if (std::isnan(var_value) || std::isnan(moments_4) || var_value <= 0) {
146
36
                dst_column_with_nullable.get_null_map_data().push_back(1);
147
36
                dst_column->insert_default();
148
36
            } else {
149
6
                dst_column_with_nullable.get_null_map_data().push_back(0);
150
                // kurtosis = E(X^4) / E(X^2)^2 - 3
151
6
                dst_column->get_data().push_back(
152
6
                        static_cast<Float64>(moments_4 / pow(var_value, 2)) - 3);
153
6
            }
154
42
            break;
155
0
        }
156
0
        default:
157
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Unknown statistics function kind");
158
84
        }
159
84
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb1EE18insert_result_intoEPKcRNS_7IColumnE
Line
Count
Source
119
21
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
120
21
        const auto& data = this->data(place);
121
21
        ColumnNullable& dst_column_with_nullable = assert_cast<ColumnNullable&>(to);
122
21
        ResultCol* dst_column =
123
21
                assert_cast<ResultCol*>(&(dst_column_with_nullable.get_nested_column()));
124
125
21
        switch (kind) {
126
21
        case STATISTICS_FUNCTION_KIND::SKEW_POP: {
127
            // If input is empty set, we will get NAN from get_population()
128
21
            Float64 var_value = data.get_population();
129
21
            Float64 moments_3 = data.get_moment_3();
130
131
21
            if (std::isnan(var_value) || std::isnan(moments_3) || var_value <= 0) {
132
18
                dst_column_with_nullable.get_null_map_data().push_back(1);
133
18
                dst_column->insert_default();
134
18
            } else {
135
3
                dst_column_with_nullable.get_null_map_data().push_back(0);
136
3
                dst_column->get_data().push_back(
137
3
                        static_cast<Float64>(moments_3 / pow(var_value, 1.5)));
138
3
            }
139
21
            break;
140
0
        }
141
0
        case STATISTICS_FUNCTION_KIND::KURT_POP: {
142
0
            Float64 var_value = data.get_population();
143
0
            Float64 moments_4 = data.get_moment_4();
144
145
0
            if (std::isnan(var_value) || std::isnan(moments_4) || var_value <= 0) {
146
0
                dst_column_with_nullable.get_null_map_data().push_back(1);
147
0
                dst_column->insert_default();
148
0
            } else {
149
0
                dst_column_with_nullable.get_null_map_data().push_back(0);
150
                // kurtosis = E(X^4) / E(X^2)^2 - 3
151
0
                dst_column->get_data().push_back(
152
0
                        static_cast<Float64>(moments_4 / pow(var_value, 2)) - 3);
153
0
            }
154
0
            break;
155
0
        }
156
0
        default:
157
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Unknown statistics function kind");
158
21
        }
159
21
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm3EEELb0EE18insert_result_intoEPKcRNS_7IColumnE
Line
Count
Source
119
21
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
120
21
        const auto& data = this->data(place);
121
21
        ColumnNullable& dst_column_with_nullable = assert_cast<ColumnNullable&>(to);
122
21
        ResultCol* dst_column =
123
21
                assert_cast<ResultCol*>(&(dst_column_with_nullable.get_nested_column()));
124
125
21
        switch (kind) {
126
21
        case STATISTICS_FUNCTION_KIND::SKEW_POP: {
127
            // If input is empty set, we will get NAN from get_population()
128
21
            Float64 var_value = data.get_population();
129
21
            Float64 moments_3 = data.get_moment_3();
130
131
21
            if (std::isnan(var_value) || std::isnan(moments_3) || var_value <= 0) {
132
18
                dst_column_with_nullable.get_null_map_data().push_back(1);
133
18
                dst_column->insert_default();
134
18
            } else {
135
3
                dst_column_with_nullable.get_null_map_data().push_back(0);
136
3
                dst_column->get_data().push_back(
137
3
                        static_cast<Float64>(moments_3 / pow(var_value, 1.5)));
138
3
            }
139
21
            break;
140
0
        }
141
0
        case STATISTICS_FUNCTION_KIND::KURT_POP: {
142
0
            Float64 var_value = data.get_population();
143
0
            Float64 moments_4 = data.get_moment_4();
144
145
0
            if (std::isnan(var_value) || std::isnan(moments_4) || var_value <= 0) {
146
0
                dst_column_with_nullable.get_null_map_data().push_back(1);
147
0
                dst_column->insert_default();
148
0
            } else {
149
0
                dst_column_with_nullable.get_null_map_data().push_back(0);
150
                // kurtosis = E(X^4) / E(X^2)^2 - 3
151
0
                dst_column->get_data().push_back(
152
0
                        static_cast<Float64>(moments_4 / pow(var_value, 2)) - 3);
153
0
            }
154
0
            break;
155
0
        }
156
0
        default:
157
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Unknown statistics function kind");
158
21
        }
159
21
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb1EE18insert_result_intoEPKcRNS_7IColumnE
Line
Count
Source
119
21
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
120
21
        const auto& data = this->data(place);
121
21
        ColumnNullable& dst_column_with_nullable = assert_cast<ColumnNullable&>(to);
122
21
        ResultCol* dst_column =
123
21
                assert_cast<ResultCol*>(&(dst_column_with_nullable.get_nested_column()));
124
125
21
        switch (kind) {
126
0
        case STATISTICS_FUNCTION_KIND::SKEW_POP: {
127
            // If input is empty set, we will get NAN from get_population()
128
0
            Float64 var_value = data.get_population();
129
0
            Float64 moments_3 = data.get_moment_3();
130
131
0
            if (std::isnan(var_value) || std::isnan(moments_3) || var_value <= 0) {
132
0
                dst_column_with_nullable.get_null_map_data().push_back(1);
133
0
                dst_column->insert_default();
134
0
            } else {
135
0
                dst_column_with_nullable.get_null_map_data().push_back(0);
136
0
                dst_column->get_data().push_back(
137
0
                        static_cast<Float64>(moments_3 / pow(var_value, 1.5)));
138
0
            }
139
0
            break;
140
0
        }
141
21
        case STATISTICS_FUNCTION_KIND::KURT_POP: {
142
21
            Float64 var_value = data.get_population();
143
21
            Float64 moments_4 = data.get_moment_4();
144
145
21
            if (std::isnan(var_value) || std::isnan(moments_4) || var_value <= 0) {
146
18
                dst_column_with_nullable.get_null_map_data().push_back(1);
147
18
                dst_column->insert_default();
148
18
            } else {
149
3
                dst_column_with_nullable.get_null_map_data().push_back(0);
150
                // kurtosis = E(X^4) / E(X^2)^2 - 3
151
3
                dst_column->get_data().push_back(
152
3
                        static_cast<Float64>(moments_4 / pow(var_value, 2)) - 3);
153
3
            }
154
21
            break;
155
0
        }
156
0
        default:
157
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Unknown statistics function kind");
158
21
        }
159
21
    }
_ZNK5doris31AggregateFunctionVarianceSimpleINS_14StatFuncOneArgILNS_13PrimitiveTypeE9ELm4EEELb0EE18insert_result_intoEPKcRNS_7IColumnE
Line
Count
Source
119
21
    void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override {
120
21
        const auto& data = this->data(place);
121
21
        ColumnNullable& dst_column_with_nullable = assert_cast<ColumnNullable&>(to);
122
21
        ResultCol* dst_column =
123
21
                assert_cast<ResultCol*>(&(dst_column_with_nullable.get_nested_column()));
124
125
21
        switch (kind) {
126
0
        case STATISTICS_FUNCTION_KIND::SKEW_POP: {
127
            // If input is empty set, we will get NAN from get_population()
128
0
            Float64 var_value = data.get_population();
129
0
            Float64 moments_3 = data.get_moment_3();
130
131
0
            if (std::isnan(var_value) || std::isnan(moments_3) || var_value <= 0) {
132
0
                dst_column_with_nullable.get_null_map_data().push_back(1);
133
0
                dst_column->insert_default();
134
0
            } else {
135
0
                dst_column_with_nullable.get_null_map_data().push_back(0);
136
0
                dst_column->get_data().push_back(
137
0
                        static_cast<Float64>(moments_3 / pow(var_value, 1.5)));
138
0
            }
139
0
            break;
140
0
        }
141
21
        case STATISTICS_FUNCTION_KIND::KURT_POP: {
142
21
            Float64 var_value = data.get_population();
143
21
            Float64 moments_4 = data.get_moment_4();
144
145
21
            if (std::isnan(var_value) || std::isnan(moments_4) || var_value <= 0) {
146
18
                dst_column_with_nullable.get_null_map_data().push_back(1);
147
18
                dst_column->insert_default();
148
18
            } else {
149
3
                dst_column_with_nullable.get_null_map_data().push_back(0);
150
                // kurtosis = E(X^4) / E(X^2)^2 - 3
151
3
                dst_column->get_data().push_back(
152
3
                        static_cast<Float64>(moments_4 / pow(var_value, 2)) - 3);
153
3
            }
154
21
            break;
155
0
        }
156
0
        default:
157
0
            throw doris::Exception(ErrorCode::INTERNAL_ERROR, "Unknown statistics function kind");
158
21
        }
159
21
    }
160
161
private:
162
    STATISTICS_FUNCTION_KIND kind;
163
};
164
165
} // namespace doris