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 | 372 | : IAggregateFunctionDataHelper<typename StatFunc::Data, |
59 | 372 | AggregateFunctionBinary<StatFunc>>(argument_types_) {}_ZN5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaISA_EE Line | Count | Source | 58 | 346 | : IAggregateFunctionDataHelper<typename StatFunc::Data, | 59 | 346 | AggregateFunctionBinary<StatFunc>>(argument_types_) {} |
_ZN5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEEC2ERKSt6vectorISt10shared_ptrIKNS_9IDataTypeEESaISA_EE Line | Count | Source | 58 | 26 | : IAggregateFunctionDataHelper<typename StatFunc::Data, | 59 | 26 | AggregateFunctionBinary<StatFunc>>(argument_types_) {} |
|
60 | | |
61 | 33 | String get_name() const override { return StatFunc::Data::name(); }_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE8get_nameB5cxx11Ev Line | Count | Source | 61 | 32 | 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 | 40 | void reset(AggregateDataPtr __restrict place) const override { this->data(place).reset(); }_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE5resetEPc Line | Count | Source | 63 | 39 | 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 | 147 | DataTypePtr get_return_type() const override { |
66 | 147 | return std::make_shared<DataTypeNumber<StatFunc::ResultPrimitiveType>>(); |
67 | 147 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE15get_return_typeEv Line | Count | Source | 65 | 96 | DataTypePtr get_return_type() const override { | 66 | 96 | return std::make_shared<DataTypeNumber<StatFunc::ResultPrimitiveType>>(); | 67 | 96 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE15get_return_typeEv Line | Count | Source | 65 | 51 | DataTypePtr get_return_type() const override { | 66 | 51 | return std::make_shared<DataTypeNumber<StatFunc::ResultPrimitiveType>>(); | 67 | 51 | } |
|
68 | | |
69 | | void add(AggregateDataPtr __restrict place, const IColumn** columns, ssize_t row_num, |
70 | 368 | Arena&) const override { |
71 | 368 | this->data(place).add( |
72 | 368 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( |
73 | 368 | static_cast<const ColVecT1&>(*columns[0]).get_data()[row_num]), |
74 | 368 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( |
75 | 368 | static_cast<const ColVecT2&>(*columns[1]).get_data()[row_num])); |
76 | 368 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE Line | Count | Source | 70 | 270 | Arena&) const override { | 71 | 270 | this->data(place).add( | 72 | 270 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( | 73 | 270 | static_cast<const ColVecT1&>(*columns[0]).get_data()[row_num]), | 74 | 270 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( | 75 | 270 | static_cast<const ColVecT2&>(*columns[1]).get_data()[row_num])); | 76 | 270 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE3addEPcPPKNS_7IColumnElRNS_5ArenaE Line | Count | Source | 70 | 98 | Arena&) const override { | 71 | 98 | this->data(place).add( | 72 | 98 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( | 73 | 98 | static_cast<const ColVecT1&>(*columns[0]).get_data()[row_num]), | 74 | 98 | static_cast<typename PrimitiveTypeTraits<ResultType>::CppType>( | 75 | 98 | static_cast<const ColVecT2&>(*columns[1]).get_data()[row_num])); | 76 | 98 | } |
|
77 | | |
78 | | void merge(AggregateDataPtr __restrict place, ConstAggregateDataPtr rhs, |
79 | 171 | Arena&) const override { |
80 | 171 | this->data(place).merge(this->data(rhs)); |
81 | 171 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE5mergeEPcPKcRNS_5ArenaE Line | Count | Source | 79 | 152 | Arena&) const override { | 80 | 152 | this->data(place).merge(this->data(rhs)); | 81 | 152 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE5mergeEPcPKcRNS_5ArenaE Line | Count | Source | 79 | 19 | Arena&) const override { | 80 | 19 | this->data(place).merge(this->data(rhs)); | 81 | 19 | } |
|
82 | | |
83 | 212 | void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { |
84 | 212 | this->data(place).write(buf); |
85 | 212 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE9serializeEPKcRNS_14BufferWritableE Line | Count | Source | 83 | 192 | void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { | 84 | 192 | this->data(place).write(buf); | 85 | 192 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE9serializeEPKcRNS_14BufferWritableE Line | Count | Source | 83 | 20 | void serialize(ConstAggregateDataPtr __restrict place, BufferWritable& buf) const override { | 84 | 20 | this->data(place).write(buf); | 85 | 20 | } |
|
86 | | |
87 | | void deserialize(AggregateDataPtr __restrict place, BufferReadable& buf, |
88 | 171 | Arena&) const override { |
89 | 171 | this->data(place).read(buf); |
90 | 171 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE Line | Count | Source | 88 | 152 | Arena&) const override { | 89 | 152 | this->data(place).read(buf); | 90 | 152 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE11deserializeEPcRNS_14BufferReadableERNS_5ArenaE Line | Count | Source | 88 | 19 | Arena&) const override { | 89 | 19 | this->data(place).read(buf); | 90 | 19 | } |
|
91 | | |
92 | 89 | void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { |
93 | 89 | const auto& data = this->data(place); |
94 | 89 | auto& dst = static_cast<ColVecResult&>(to).get_data(); |
95 | 89 | dst.push_back(data.get()); |
96 | 89 | } _ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_10CorrMomentEEEE18insert_result_intoEPKcRNS_7IColumnE Line | Count | Source | 92 | 69 | void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { | 93 | 69 | const auto& data = this->data(place); | 94 | 69 | auto& dst = static_cast<ColVecResult&>(to).get_data(); | 95 | 69 | dst.push_back(data.get()); | 96 | 69 | } |
_ZNK5doris23AggregateFunctionBinaryINS_8StatFuncILNS_13PrimitiveTypeE9ENS_17CorrMomentWelfordEEEE18insert_result_intoEPKcRNS_7IColumnE Line | Count | Source | 92 | 20 | void insert_result_into(ConstAggregateDataPtr __restrict place, IColumn& to) const override { | 93 | 20 | const auto& data = this->data(place); | 94 | 20 | auto& dst = static_cast<ColVecResult&>(to).get_data(); | 95 | 20 | dst.push_back(data.get()); | 96 | 20 | } |
|
97 | | }; |
98 | | |
99 | | } // namespace doris |
100 | | |
101 | | #include "common/compile_check_end.h" |