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 | | |
35 | | template <PrimitiveType T, template <PrimitiveType> typename Moments> |
36 | | struct StatFunc { |
37 | | using ColVecT1 = typename PrimitiveTypeTraits<T>::ColumnType; |
38 | | using ColVecT2 = ColVecT1; |
39 | | using Data = Moments<TYPE_DOUBLE>; |
40 | | static constexpr PrimitiveType ResultPrimitiveType = TYPE_DOUBLE; |
41 | | }; |
42 | | |
43 | | template <typename StatFunc> |
44 | | struct AggregateFunctionBinary |
45 | | : public IAggregateFunctionDataHelper<typename StatFunc::Data, |
46 | | AggregateFunctionBinary<StatFunc>>, |
47 | | MultiExpression, |
48 | | NullableAggregateFunction { |
49 | | static constexpr PrimitiveType ResultType = StatFunc::ResultPrimitiveType; |
50 | | |
51 | | using ColVecT1 = typename StatFunc::ColVecT1; |
52 | | using ColVecT2 = typename StatFunc::ColVecT2; |
53 | | using ColVecResult = ColumnVector<ResultType>; |
54 | | static constexpr UInt32 num_args = 2; |
55 | | |
56 | | AggregateFunctionBinary(const DataTypes& argument_types_) |
57 | 427 | : IAggregateFunctionDataHelper<typename StatFunc::Data, |
58 | 427 | AggregateFunctionBinary<StatFunc>>(argument_types_) {}_ZN5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaISA_EE Line | Count | Source | 57 | 401 | : IAggregateFunctionDataHelper<typename StatFunc::Data, | 58 | 401 | AggregateFunctionBinary<StatFunc>>(argument_types_) {} |
_ZN5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaISA_EE Line | Count | Source | 57 | 26 | : IAggregateFunctionDataHelper<typename StatFunc::Data, | 58 | 26 | AggregateFunctionBinary<StatFunc>>(argument_types_) {} |
|
59 | | |
60 | 33 | String get_name() const override { return StatFunc::Data::name(); }_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE8get_nameB5cxx11Ev Line | Count | Source | 60 | 32 | String get_name() const override { return StatFunc::Data::name(); } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE8get_nameB5cxx11Ev Line | Count | Source | 60 | 1 | String get_name() const override { return StatFunc::Data::name(); } |
|
61 | | |
62 | 40 | void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE5resetEPc Line | Count | Source | 62 | 39 | void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE5resetEPc Line | Count | Source | 62 | 1 | void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); } |
|
63 | | |
64 | 147 | DataTypePtr get_return_type() const override { |
65 | 147 | return std::make_shared<DataTypeNumber<StatFunc::ResultPrimitiveType>>(); |
66 | 147 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE15get_return_typeEv Line | Count | Source | 64 | 96 | DataTypePtr get_return_type() const override { | 65 | 96 | return std::make_shared<DataTypeNumber<StatFunc::ResultPrimitiveType>>(); | 66 | 96 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE15get_return_typeEv Line | Count | Source | 64 | 51 | DataTypePtr get_return_type() const override { | 65 | 51 | return std::make_shared<DataTypeNumber<StatFunc::ResultPrimitiveType>>(); | 66 | 51 | } |
|
67 | | |
68 | | void add(AggregateDataPtr __restrict place, const IColumn** columns, ssize_t row_num, |
69 | 366 | Arena&) const override { |
70 | 366 | this->data(place).add( |
71 | 366 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( |
72 | 366 | static_cast<const ColVecT1&>(*columns[0]).get_data()[row_num]), |
73 | 366 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( |
74 | 366 | static_cast<const ColVecT2&>(*columns[1]).get_data()[row_num])); |
75 | 366 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE Line | Count | Source | 69 | 268 | Arena&) const override { | 70 | 268 | this->data(place).add( | 71 | 268 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( | 72 | 268 | static_cast<const ColVecT1&>(*columns[0]).get_data()[row_num]), | 73 | 268 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( | 74 | 268 | static_cast<const ColVecT2&>(*columns[1]).get_data()[row_num])); | 75 | 268 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE Line | Count | Source | 69 | 98 | Arena&) const override { | 70 | 98 | this->data(place).add( | 71 | 98 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( | 72 | 98 | static_cast<const ColVecT1&>(*columns[0]).get_data()[row_num]), | 73 | 98 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( | 74 | 98 | static_cast<const ColVecT2&>(*columns[1]).get_data()[row_num])); | 75 | 98 | } |
|
76 | | |
77 | | void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, |
78 | 204 | Arena&) const override { |
79 | 204 | this->data(place).merge(this->data(rhs)); |
80 | 204 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE5mergeEPcPKcRNS_5ArenaE Line | Count | Source | 78 | 163 | Arena&) const override { | 79 | 163 | this->data(place).merge(this->data(rhs)); | 80 | 163 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE5mergeEPcPKcRNS_5ArenaE Line | Count | Source | 78 | 41 | Arena&) const override { | 79 | 41 | this->data(place).merge(this->data(rhs)); | 80 | 41 | } |
|
81 | | |
82 | 245 | void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { |
83 | 245 | this->data(place).write(buf); |
84 | 245 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE9serializeEPKcRNS_14BufferWritableE Line | Count | Source | 82 | 203 | void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { | 83 | 203 | this->data(place).write(buf); | 84 | 203 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE9serializeEPKcRNS_14BufferWritableE Line | Count | Source | 82 | 42 | void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { | 83 | 42 | this->data(place).write(buf); | 84 | 42 | } |
|
85 | | |
86 | | void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, |
87 | 204 | Arena&) const override { |
88 | 204 | this->data(place).read(buf); |
89 | 204 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE Line | Count | Source | 87 | 163 | Arena&) const override { | 88 | 163 | this->data(place).read(buf); | 89 | 163 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE Line | Count | Source | 87 | 41 | Arena&) const override { | 88 | 41 | this->data(place).read(buf); | 89 | 41 | } |
|
90 | | |
91 | 89 | void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { |
92 | 89 | const auto& data = this->data(place); |
93 | 89 | auto& dst = static_cast<ColVecResult&>(to).get_data(); |
94 | 89 | dst.push_back(data.get()); |
95 | 89 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE18insert_result_intoEPKcRNS_7IColumnE Line | Count | Source | 91 | 69 | void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { | 92 | 69 | const auto& data = this->data(place); | 93 | 69 | auto& dst = static_cast<ColVecResult&>(to).get_data(); | 94 | 69 | dst.push_back(data.get()); | 95 | 69 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE18insert_result_intoEPKcRNS_7IColumnE Line | Count | Source | 91 | 20 | void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { | 92 | 20 | const auto& data = this->data(place); | 93 | 20 | auto& dst = static_cast<ColVecResult&>(to).get_data(); | 94 | 20 | dst.push_back(data.get()); | 95 | 20 | } |
|
96 | | }; |
97 | | |
98 | | } // namespace doris |