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