/root/doris/be/src/vec/functions/math.cpp
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 | | #include <cstdint> |
19 | | #include <cstring> |
20 | | |
21 | | // IWYU pragma: no_include <bits/std_abs.h> |
22 | | #include <dlfcn.h> |
23 | | |
24 | | #include <cmath> |
25 | | #include <string> |
26 | | #include <type_traits> |
27 | | |
28 | | #include "common/status.h" |
29 | | #include "util/debug/leak_annotations.h" |
30 | | #include "vec/columns/column.h" |
31 | | #include "vec/columns/column_string.h" |
32 | | #include "vec/columns/column_vector.h" |
33 | | #include "vec/core/types.h" |
34 | | #include "vec/data_types/data_type_string.h" |
35 | | #include "vec/data_types/number_traits.h" |
36 | | #include "vec/functions/function_const.h" |
37 | | #include "vec/functions/function_math_log.h" |
38 | | #include "vec/functions/function_math_unary.h" |
39 | | #include "vec/functions/function_math_unary_alway_nullable.h" |
40 | | #include "vec/functions/function_totype.h" |
41 | | #include "vec/functions/function_unary_arithmetic.h" |
42 | | #include "vec/functions/simple_function_factory.h" |
43 | | #include "vec/utils/stringop_substring.h" |
44 | | |
45 | | namespace doris::vectorized { |
46 | | |
47 | | struct AcosName { |
48 | | static constexpr auto name = "acos"; |
49 | | // https://dev.mysql.com/doc/refman/8.4/en/mathematical-functions.html#function_acos |
50 | 4 | static constexpr bool is_invalid_input(Float64 x) { return x < -1 || x > 1; } |
51 | | }; |
52 | | using FunctionAcos = |
53 | | FunctionMathUnaryAlwayNullable<UnaryFunctionPlainAlwayNullable<AcosName, std::acos>>; |
54 | | |
55 | | struct AcoshName { |
56 | | static constexpr auto name = "acosh"; |
57 | 10 | static constexpr bool is_invalid_input(Float64 x) { return x < 1; } |
58 | | }; |
59 | | using FunctionAcosh = |
60 | | FunctionMathUnaryAlwayNullable<UnaryFunctionPlainAlwayNullable<AcoshName, std::acosh>>; |
61 | | |
62 | | struct AsinName { |
63 | | static constexpr auto name = "asin"; |
64 | | // https://dev.mysql.com/doc/refman/8.4/en/mathematical-functions.html#function_asin |
65 | 4 | static constexpr bool is_invalid_input(Float64 x) { return x < -1 || x > 1; } |
66 | | }; |
67 | | using FunctionAsin = |
68 | | FunctionMathUnaryAlwayNullable<UnaryFunctionPlainAlwayNullable<AsinName, std::asin>>; |
69 | | |
70 | | struct AsinhName { |
71 | | static constexpr auto name = "asinh"; |
72 | | }; |
73 | | using FunctionAsinh = FunctionMathUnary<UnaryFunctionPlain<AsinhName, std::asinh>>; |
74 | | |
75 | | struct AtanName { |
76 | | static constexpr auto name = "atan"; |
77 | | }; |
78 | | using FunctionAtan = FunctionMathUnary<UnaryFunctionPlain<AtanName, std::atan>>; |
79 | | |
80 | | struct AtanhName { |
81 | | static constexpr auto name = "atanh"; |
82 | 10 | static constexpr bool is_invalid_input(Float64 x) { return x <= -1 || x >= 1; } |
83 | | }; |
84 | | using FunctionAtanh = |
85 | | FunctionMathUnaryAlwayNullable<UnaryFunctionPlainAlwayNullable<AtanhName, std::atanh>>; |
86 | | |
87 | | struct CosName { |
88 | | static constexpr auto name = "cos"; |
89 | | }; |
90 | | using FunctionCos = FunctionMathUnary<UnaryFunctionPlain<CosName, std::cos>>; |
91 | | |
92 | | struct CoshName { |
93 | | static constexpr auto name = "cosh"; |
94 | | }; |
95 | | using FunctionCosh = FunctionMathUnary<UnaryFunctionPlain<CoshName, std::cosh>>; |
96 | | |
97 | | struct EImpl { |
98 | | static constexpr auto name = "e"; |
99 | | static constexpr double value = 2.7182818284590452353602874713526624977572470; |
100 | | }; |
101 | | using FunctionE = FunctionMathConstFloat64<EImpl>; |
102 | | |
103 | | struct PiImpl { |
104 | | static constexpr auto name = "pi"; |
105 | | static constexpr double value = 3.1415926535897932384626433832795028841971693; |
106 | | }; |
107 | | using FunctionPi = FunctionMathConstFloat64<PiImpl>; |
108 | | |
109 | | struct ExpName { |
110 | | static constexpr auto name = "exp"; |
111 | | }; |
112 | | using FunctionExp = FunctionMathUnary<UnaryFunctionPlain<ExpName, std::exp>>; |
113 | | |
114 | | template <typename A> |
115 | | struct SignImpl { |
116 | | static constexpr PrimitiveType ResultType = TYPE_TINYINT; |
117 | 6 | static inline UInt8 apply(A a) { |
118 | | if constexpr (IsDecimalNumber<A> || std::is_floating_point_v<A>) |
119 | 3 | return static_cast<UInt8>(a < A(0) ? -1 : a == A(0) ? 0 : 1); |
120 | | else if constexpr (IsSignedV<A>) |
121 | 3 | return static_cast<UInt8>(a < 0 ? -1 : a == 0 ? 0 : 1); |
122 | | else if constexpr (IsUnsignedV<A>) |
123 | 0 | return static_cast<UInt8>(a == 0 ? 0 : 1); |
124 | 6 | } Unexecuted instantiation: _ZN5doris10vectorized8SignImplIhE5applyEh Unexecuted instantiation: _ZN5doris10vectorized8SignImplIaE5applyEa Unexecuted instantiation: _ZN5doris10vectorized8SignImplIsE5applyEs _ZN5doris10vectorized8SignImplIiE5applyEi Line | Count | Source | 117 | 3 | static inline UInt8 apply(A a) { | 118 | | if constexpr (IsDecimalNumber<A> || std::is_floating_point_v<A>) | 119 | | return static_cast<UInt8>(a < A(0) ? -1 : a == A(0) ? 0 : 1); | 120 | | else if constexpr (IsSignedV<A>) | 121 | 3 | return static_cast<UInt8>(a < 0 ? -1 : a == 0 ? 0 : 1); | 122 | | else if constexpr (IsUnsignedV<A>) | 123 | | return static_cast<UInt8>(a == 0 ? 0 : 1); | 124 | 3 | } |
Unexecuted instantiation: _ZN5doris10vectorized8SignImplIlE5applyEl Unexecuted instantiation: _ZN5doris10vectorized8SignImplInE5applyEn Unexecuted instantiation: _ZN5doris10vectorized8SignImplIfE5applyEf _ZN5doris10vectorized8SignImplIdE5applyEd Line | Count | Source | 117 | 3 | static inline UInt8 apply(A a) { | 118 | | if constexpr (IsDecimalNumber<A> || std::is_floating_point_v<A>) | 119 | 3 | return static_cast<UInt8>(a < A(0) ? -1 : a == A(0) ? 0 : 1); | 120 | | else if constexpr (IsSignedV<A>) | 121 | | return static_cast<UInt8>(a < 0 ? -1 : a == 0 ? 0 : 1); | 122 | | else if constexpr (IsUnsignedV<A>) | 123 | | return static_cast<UInt8>(a == 0 ? 0 : 1); | 124 | 3 | } |
|
125 | | }; |
126 | | |
127 | | struct NameSign { |
128 | | static constexpr auto name = "sign"; |
129 | | }; |
130 | | using FunctionSign = FunctionUnaryArithmetic<SignImpl, NameSign>; |
131 | | |
132 | | template <typename A> |
133 | | struct AbsImpl { |
134 | | static constexpr PrimitiveType ResultType = NumberTraits::ResultOfAbs<A>::Type; |
135 | | |
136 | 12 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { |
137 | | if constexpr (IsDecimalNumber<A>) |
138 | 0 | return a < A(0) ? A(-a) : a; |
139 | | else if constexpr (IsIntegralV<A> && IsSignedV<A>) |
140 | 7 | return a < A(0) ? static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>( |
141 | 3 | ~a) + |
142 | 3 | 1 |
143 | 7 | : a; |
144 | | else if constexpr (IsIntegralV<A> && IsUnsignedV<A>) |
145 | 0 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>(a); |
146 | | else if constexpr (std::is_floating_point_v<A>) |
147 | 5 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>( |
148 | 5 | std::abs(a)); |
149 | 12 | } Unexecuted instantiation: _ZN5doris10vectorized7AbsImplIhE5applyEh Unexecuted instantiation: _ZN5doris10vectorized7AbsImplIaE5applyEa Unexecuted instantiation: _ZN5doris10vectorized7AbsImplIsE5applyEs _ZN5doris10vectorized7AbsImplIiE5applyEi Line | Count | Source | 136 | 7 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { | 137 | | if constexpr (IsDecimalNumber<A>) | 138 | | return a < A(0) ? A(-a) : a; | 139 | | else if constexpr (IsIntegralV<A> && IsSignedV<A>) | 140 | 7 | return a < A(0) ? static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>( | 141 | 3 | ~a) + | 142 | 3 | 1 | 143 | 7 | : a; | 144 | | else if constexpr (IsIntegralV<A> && IsUnsignedV<A>) | 145 | | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>(a); | 146 | | else if constexpr (std::is_floating_point_v<A>) | 147 | | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>( | 148 | | std::abs(a)); | 149 | 7 | } |
Unexecuted instantiation: _ZN5doris10vectorized7AbsImplIlE5applyEl Unexecuted instantiation: _ZN5doris10vectorized7AbsImplInE5applyEn Unexecuted instantiation: _ZN5doris10vectorized7AbsImplIfE5applyEf _ZN5doris10vectorized7AbsImplIdE5applyEd Line | Count | Source | 136 | 5 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { | 137 | | if constexpr (IsDecimalNumber<A>) | 138 | | return a < A(0) ? A(-a) : a; | 139 | | else if constexpr (IsIntegralV<A> && IsSignedV<A>) | 140 | | return a < A(0) ? static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>( | 141 | | ~a) + | 142 | | 1 | 143 | | : a; | 144 | | else if constexpr (IsIntegralV<A> && IsUnsignedV<A>) | 145 | | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>(a); | 146 | | else if constexpr (std::is_floating_point_v<A>) | 147 | 5 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>( | 148 | 5 | std::abs(a)); | 149 | 5 | } |
Unexecuted instantiation: _ZN5doris10vectorized7AbsImplINS0_7DecimalIiEEE5applyES3_ Unexecuted instantiation: _ZN5doris10vectorized7AbsImplINS0_7DecimalIlEEE5applyES3_ Unexecuted instantiation: _ZN5doris10vectorized7AbsImplINS0_7DecimalInEEE5applyES3_ Unexecuted instantiation: _ZN5doris10vectorized7AbsImplINS0_12Decimal128V3EE5applyES2_ Unexecuted instantiation: _ZN5doris10vectorized7AbsImplINS0_7DecimalIN4wide7integerILm256EiEEEEE5applyES6_ |
150 | | }; |
151 | | |
152 | | struct NameAbs { |
153 | | static constexpr auto name = "abs"; |
154 | | }; |
155 | | |
156 | | template <typename A> |
157 | | struct ResultOfUnaryFunc; |
158 | | |
159 | | template <> |
160 | | struct ResultOfUnaryFunc<UInt8> { |
161 | | static constexpr PrimitiveType ResultType = TYPE_BOOLEAN; |
162 | | }; |
163 | | |
164 | | template <> |
165 | | struct ResultOfUnaryFunc<Int8> { |
166 | | static constexpr PrimitiveType ResultType = TYPE_TINYINT; |
167 | | }; |
168 | | |
169 | | template <> |
170 | | struct ResultOfUnaryFunc<Int16> { |
171 | | static constexpr PrimitiveType ResultType = TYPE_SMALLINT; |
172 | | }; |
173 | | |
174 | | template <> |
175 | | struct ResultOfUnaryFunc<Int32> { |
176 | | static constexpr PrimitiveType ResultType = TYPE_INT; |
177 | | }; |
178 | | |
179 | | template <> |
180 | | struct ResultOfUnaryFunc<Int64> { |
181 | | static constexpr PrimitiveType ResultType = TYPE_BIGINT; |
182 | | }; |
183 | | |
184 | | template <> |
185 | | struct ResultOfUnaryFunc<Int128> { |
186 | | static constexpr PrimitiveType ResultType = TYPE_LARGEINT; |
187 | | }; |
188 | | |
189 | | template <> |
190 | | struct ResultOfUnaryFunc<Decimal32> { |
191 | | static constexpr PrimitiveType ResultType = TYPE_DECIMAL32; |
192 | | }; |
193 | | |
194 | | template <> |
195 | | struct ResultOfUnaryFunc<Decimal64> { |
196 | | static constexpr PrimitiveType ResultType = TYPE_DECIMAL64; |
197 | | }; |
198 | | |
199 | | template <> |
200 | | struct ResultOfUnaryFunc<Decimal128V3> { |
201 | | static constexpr PrimitiveType ResultType = TYPE_DECIMAL128I; |
202 | | }; |
203 | | |
204 | | template <> |
205 | | struct ResultOfUnaryFunc<Decimal128V2> { |
206 | | static constexpr PrimitiveType ResultType = TYPE_DECIMALV2; |
207 | | }; |
208 | | |
209 | | template <> |
210 | | struct ResultOfUnaryFunc<Decimal256> { |
211 | | static constexpr PrimitiveType ResultType = TYPE_DECIMAL256; |
212 | | }; |
213 | | |
214 | | template <> |
215 | | struct ResultOfUnaryFunc<float> { |
216 | | static constexpr PrimitiveType ResultType = TYPE_FLOAT; |
217 | | }; |
218 | | |
219 | | template <> |
220 | | struct ResultOfUnaryFunc<double> { |
221 | | static constexpr PrimitiveType ResultType = TYPE_DOUBLE; |
222 | | }; |
223 | | |
224 | | using FunctionAbs = FunctionUnaryArithmetic<AbsImpl, NameAbs>; |
225 | | |
226 | | template <typename A> |
227 | | struct NegativeImpl { |
228 | | static constexpr PrimitiveType ResultType = ResultOfUnaryFunc<A>::ResultType; |
229 | | |
230 | 8 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { return -a; } Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplIhE5applyEh Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplIaE5applyEa Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplIsE5applyEs _ZN5doris10vectorized12NegativeImplIiE5applyEi Line | Count | Source | 230 | 4 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { return -a; } |
Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplIlE5applyEl Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplInE5applyEn Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplIfE5applyEf _ZN5doris10vectorized12NegativeImplIdE5applyEd Line | Count | Source | 230 | 4 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { return -a; } |
Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplINS0_7DecimalIiEEE5applyES3_ Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplINS0_7DecimalIlEEE5applyES3_ Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplINS0_7DecimalInEEE5applyES3_ Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplINS0_12Decimal128V3EE5applyES2_ Unexecuted instantiation: _ZN5doris10vectorized12NegativeImplINS0_7DecimalIN4wide7integerILm256EiEEEEE5applyES6_ |
231 | | }; |
232 | | |
233 | | struct NameNegative { |
234 | | static constexpr auto name = "negative"; |
235 | | }; |
236 | | |
237 | | using FunctionNegative = FunctionUnaryArithmetic<NegativeImpl, NameNegative>; |
238 | | |
239 | | template <typename A> |
240 | | struct PositiveImpl { |
241 | | static constexpr PrimitiveType ResultType = ResultOfUnaryFunc<A>::ResultType; |
242 | | |
243 | 12 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { |
244 | 12 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>(a); |
245 | 12 | } Unexecuted instantiation: _ZN5doris10vectorized12PositiveImplIhE5applyEh Unexecuted instantiation: _ZN5doris10vectorized12PositiveImplIaE5applyEa Unexecuted instantiation: _ZN5doris10vectorized12PositiveImplIsE5applyEs _ZN5doris10vectorized12PositiveImplIiE5applyEi Line | Count | Source | 243 | 4 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { | 244 | 4 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>(a); | 245 | 4 | } |
Unexecuted instantiation: _ZN5doris10vectorized12PositiveImplIlE5applyEl Unexecuted instantiation: _ZN5doris10vectorized12PositiveImplInE5applyEn Unexecuted instantiation: _ZN5doris10vectorized12PositiveImplIfE5applyEf _ZN5doris10vectorized12PositiveImplIdE5applyEd Line | Count | Source | 243 | 4 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { | 244 | 4 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>(a); | 245 | 4 | } |
Unexecuted instantiation: _ZN5doris10vectorized12PositiveImplINS0_7DecimalIiEEE5applyES3_ _ZN5doris10vectorized12PositiveImplINS0_7DecimalIlEEE5applyES3_ Line | Count | Source | 243 | 4 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { | 244 | 4 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>(a); | 245 | 4 | } |
Unexecuted instantiation: _ZN5doris10vectorized12PositiveImplINS0_7DecimalInEEE5applyES3_ Unexecuted instantiation: _ZN5doris10vectorized12PositiveImplINS0_12Decimal128V3EE5applyES2_ Unexecuted instantiation: _ZN5doris10vectorized12PositiveImplINS0_7DecimalIN4wide7integerILm256EiEEEEE5applyES6_ |
246 | | }; |
247 | | |
248 | | struct NamePositive { |
249 | | static constexpr auto name = "positive"; |
250 | | }; |
251 | | |
252 | | using FunctionPositive = FunctionUnaryArithmetic<PositiveImpl, NamePositive>; |
253 | | |
254 | | struct UnaryFunctionPlainSin { |
255 | | using Type = DataTypeFloat64; |
256 | | static constexpr auto name = "sin"; |
257 | | using FuncType = double (*)(double); |
258 | | |
259 | 1 | static FuncType get_sin_func() { |
260 | | #ifndef BE_TEST |
261 | | void* handle = dlopen("libm.so.6", RTLD_LAZY); |
262 | | if (handle) { |
263 | | if (auto sin_func = (double (*)(double))dlsym(handle, "sin"); sin_func) { |
264 | | return sin_func; |
265 | | } |
266 | | dlclose(handle); |
267 | | } |
268 | | #endif |
269 | 1 | return std::sin; |
270 | 1 | } |
271 | | |
272 | 5 | static void execute(const double* src, double* dst) { |
273 | 5 | static auto sin_func = get_sin_func(); |
274 | 5 | *dst = sin_func(*src); |
275 | 5 | } |
276 | | }; |
277 | | |
278 | | using FunctionSin = FunctionMathUnary<UnaryFunctionPlainSin>; |
279 | | |
280 | | struct SinhName { |
281 | | static constexpr auto name = "sinh"; |
282 | | }; |
283 | | using FunctionSinh = FunctionMathUnary<UnaryFunctionPlain<SinhName, std::sinh>>; |
284 | | |
285 | | struct SqrtName { |
286 | | static constexpr auto name = "sqrt"; |
287 | | // https://dev.mysql.com/doc/refman/8.4/en/mathematical-functions.html#function_sqrt |
288 | 4 | static constexpr bool is_invalid_input(Float64 x) { return x < 0; } |
289 | | }; |
290 | | using FunctionSqrt = |
291 | | FunctionMathUnaryAlwayNullable<UnaryFunctionPlainAlwayNullable<SqrtName, std::sqrt>>; |
292 | | |
293 | | struct CbrtName { |
294 | | static constexpr auto name = "cbrt"; |
295 | | }; |
296 | | using FunctionCbrt = FunctionMathUnary<UnaryFunctionPlain<CbrtName, std::cbrt>>; |
297 | | |
298 | | struct TanName { |
299 | | static constexpr auto name = "tan"; |
300 | | }; |
301 | | using FunctionTan = FunctionMathUnary<UnaryFunctionPlain<TanName, std::tan>>; |
302 | | |
303 | | struct TanhName { |
304 | | static constexpr auto name = "tanh"; |
305 | | }; |
306 | | using FunctionTanh = FunctionMathUnary<UnaryFunctionPlain<TanhName, std::tanh>>; |
307 | | |
308 | | struct CotName { |
309 | | static constexpr auto name = "cot"; |
310 | | }; |
311 | 2 | double cot(double x) { |
312 | 2 | return 1.0 / std::tan(x); |
313 | 2 | } |
314 | | using FunctionCot = FunctionMathUnary<UnaryFunctionPlain<CotName, cot>>; |
315 | | |
316 | | struct SecName { |
317 | | static constexpr auto name = "sec"; |
318 | | }; |
319 | 2 | double sec(double x) { |
320 | 2 | return 1.0 / std::cos(x); |
321 | 2 | } |
322 | | using FunctionSec = FunctionMathUnary<UnaryFunctionPlain<SecName, sec>>; |
323 | | |
324 | | struct CscName { |
325 | | static constexpr auto name = "csc"; |
326 | | }; |
327 | 3 | double csc(double x) { |
328 | 3 | return 1.0 / std::sin(x); |
329 | 3 | } |
330 | | using FunctionCosec = FunctionMathUnary<UnaryFunctionPlain<CscName, csc>>; |
331 | | |
332 | | template <typename A> |
333 | | struct RadiansImpl { |
334 | | static constexpr PrimitiveType ResultType = ResultOfUnaryFunc<A>::ResultType; |
335 | | |
336 | 4 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { |
337 | 4 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>( |
338 | 4 | a * PiImpl::value / 180.0); |
339 | 4 | } Unexecuted instantiation: _ZN5doris10vectorized11RadiansImplIhE5applyEh Unexecuted instantiation: _ZN5doris10vectorized11RadiansImplIaE5applyEa Unexecuted instantiation: _ZN5doris10vectorized11RadiansImplIsE5applyEs Unexecuted instantiation: _ZN5doris10vectorized11RadiansImplIiE5applyEi Unexecuted instantiation: _ZN5doris10vectorized11RadiansImplIlE5applyEl Unexecuted instantiation: _ZN5doris10vectorized11RadiansImplInE5applyEn Unexecuted instantiation: _ZN5doris10vectorized11RadiansImplIfE5applyEf _ZN5doris10vectorized11RadiansImplIdE5applyEd Line | Count | Source | 336 | 4 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { | 337 | 4 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>( | 338 | 4 | a * PiImpl::value / 180.0); | 339 | 4 | } |
|
340 | | }; |
341 | | |
342 | | struct NameRadians { |
343 | | static constexpr auto name = "radians"; |
344 | | }; |
345 | | |
346 | | using FunctionRadians = FunctionUnaryArithmetic<RadiansImpl, NameRadians>; |
347 | | |
348 | | template <typename A> |
349 | | struct DegreesImpl { |
350 | | static constexpr PrimitiveType ResultType = ResultOfUnaryFunc<A>::ResultType; |
351 | | |
352 | 4 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { |
353 | 4 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>(a * 180.0 / |
354 | 4 | PiImpl::value); |
355 | 4 | } Unexecuted instantiation: _ZN5doris10vectorized11DegreesImplIhE5applyEh Unexecuted instantiation: _ZN5doris10vectorized11DegreesImplIaE5applyEa Unexecuted instantiation: _ZN5doris10vectorized11DegreesImplIsE5applyEs Unexecuted instantiation: _ZN5doris10vectorized11DegreesImplIiE5applyEi Unexecuted instantiation: _ZN5doris10vectorized11DegreesImplIlE5applyEl Unexecuted instantiation: _ZN5doris10vectorized11DegreesImplInE5applyEn Unexecuted instantiation: _ZN5doris10vectorized11DegreesImplIfE5applyEf _ZN5doris10vectorized11DegreesImplIdE5applyEd Line | Count | Source | 352 | 4 | static inline typename PrimitiveTypeTraits<ResultType>::ColumnItemType apply(A a) { | 353 | 4 | return static_cast<typename PrimitiveTypeTraits<ResultType>::ColumnItemType>(a * 180.0 / | 354 | 4 | PiImpl::value); | 355 | 4 | } |
|
356 | | }; |
357 | | |
358 | | struct NameDegrees { |
359 | | static constexpr auto name = "degrees"; |
360 | | }; |
361 | | |
362 | | using FunctionDegrees = FunctionUnaryArithmetic<DegreesImpl, NameDegrees>; |
363 | | |
364 | | struct NameBin { |
365 | | static constexpr auto name = "bin"; |
366 | | }; |
367 | | struct BinImpl { |
368 | | using ReturnType = DataTypeString; |
369 | | static constexpr auto PrimitiveTypeImpl = PrimitiveType::TYPE_BIGINT; |
370 | | using Type = Int64; |
371 | | using ReturnColumnType = ColumnString; |
372 | | |
373 | 4 | static std::string bin_impl(Int64 value) { |
374 | 4 | uint64_t n = static_cast<uint64_t>(value); |
375 | 4 | const size_t max_bits = sizeof(uint64_t) * 8; |
376 | 4 | char result[max_bits]; |
377 | 4 | uint32_t index = max_bits; |
378 | 7 | do { |
379 | 7 | result[--index] = '0' + (n & 1); |
380 | 7 | } while (n >>= 1); |
381 | 4 | return std::string(result + index, max_bits - index); |
382 | 4 | } |
383 | | |
384 | | static Status vector(const ColumnInt64::Container& data, ColumnString::Chars& res_data, |
385 | 1 | ColumnString::Offsets& res_offsets) { |
386 | 1 | res_offsets.resize(data.size()); |
387 | 1 | size_t input_size = res_offsets.size(); |
388 | | |
389 | 5 | for (size_t i = 0; i < input_size; ++i) { |
390 | 4 | StringOP::push_value_string(bin_impl(data[i]), i, res_data, res_offsets); |
391 | 4 | } |
392 | 1 | return Status::OK(); |
393 | 1 | } |
394 | | }; |
395 | | |
396 | | using FunctionBin = FunctionUnaryToType<BinImpl, NameBin>; |
397 | | |
398 | | struct PowImpl { |
399 | | static constexpr auto name = "pow"; |
400 | | static constexpr bool need_replace_null_data_to_default = true; |
401 | | static constexpr bool is_nullable = false; |
402 | 4 | static inline double apply(double a, double b) { return std::pow(a, b); } |
403 | | }; |
404 | | struct LogImpl { |
405 | | static constexpr auto name = "log"; |
406 | | static constexpr bool need_replace_null_data_to_default = false; |
407 | | static constexpr bool is_nullable = true; |
408 | | static constexpr double EPSILON = 1e-9; |
409 | 6 | static inline double apply(double a, double b, UInt8& is_null) { |
410 | 6 | is_null = a <= 0 || b <= 0 || std::fabs(a - 1.0) < EPSILON; |
411 | 6 | return std::log(b) / std::log(a); |
412 | 6 | } |
413 | | }; |
414 | | struct Atan2Impl { |
415 | | static constexpr auto name = "atan2"; |
416 | | static constexpr bool need_replace_null_data_to_default = false; |
417 | | static constexpr bool is_nullable = false; |
418 | 21 | static inline double apply(double a, double b) { return std::atan2(a, b); } |
419 | | }; |
420 | | |
421 | | template <typename Impl> |
422 | | class FunctionMath : public IFunction { |
423 | | public: |
424 | | static constexpr auto name = Impl::name; |
425 | | |
426 | 3 | String get_name() const override { return name; } _ZNK5doris10vectorized12FunctionMathINS0_7LogImplEE8get_nameB5cxx11Ev Line | Count | Source | 426 | 1 | String get_name() const override { return name; } |
_ZNK5doris10vectorized12FunctionMathINS0_7PowImplEE8get_nameB5cxx11Ev Line | Count | Source | 426 | 1 | String get_name() const override { return name; } |
_ZNK5doris10vectorized12FunctionMathINS0_9Atan2ImplEE8get_nameB5cxx11Ev Line | Count | Source | 426 | 1 | String get_name() const override { return name; } |
|
427 | | |
428 | 27 | static FunctionPtr create() { return std::make_shared<FunctionMath<Impl>>(); } _ZN5doris10vectorized12FunctionMathINS0_7LogImplEE6createEv Line | Count | Source | 428 | 3 | static FunctionPtr create() { return std::make_shared<FunctionMath<Impl>>(); } |
_ZN5doris10vectorized12FunctionMathINS0_7PowImplEE6createEv Line | Count | Source | 428 | 3 | static FunctionPtr create() { return std::make_shared<FunctionMath<Impl>>(); } |
_ZN5doris10vectorized12FunctionMathINS0_9Atan2ImplEE6createEv Line | Count | Source | 428 | 21 | static FunctionPtr create() { return std::make_shared<FunctionMath<Impl>>(); } |
|
429 | | |
430 | 21 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
431 | 21 | auto res = std::make_shared<DataTypeFloat64>(); |
432 | 21 | return Impl::is_nullable ? make_nullable(res) : res; |
433 | 21 | } _ZNK5doris10vectorized12FunctionMathINS0_7LogImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS0_9IDataTypeEESaIS8_EE Line | Count | Source | 430 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 431 | 1 | auto res = std::make_shared<DataTypeFloat64>(); | 432 | 1 | return Impl::is_nullable ? make_nullable(res) : res; | 433 | 1 | } |
_ZNK5doris10vectorized12FunctionMathINS0_7PowImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS0_9IDataTypeEESaIS8_EE Line | Count | Source | 430 | 1 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 431 | 1 | auto res = std::make_shared<DataTypeFloat64>(); | 432 | 1 | return Impl::is_nullable ? make_nullable(res) : res; | 433 | 1 | } |
_ZNK5doris10vectorized12FunctionMathINS0_9Atan2ImplEE20get_return_type_implERKSt6vectorISt10shared_ptrIKNS0_9IDataTypeEESaIS8_EE Line | Count | Source | 430 | 19 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { | 431 | 19 | auto res = std::make_shared<DataTypeFloat64>(); | 432 | 19 | return Impl::is_nullable ? make_nullable(res) : res; | 433 | 19 | } |
|
434 | 18 | bool need_replace_null_data_to_default() const override { |
435 | 18 | return Impl::need_replace_null_data_to_default; |
436 | 18 | } _ZNK5doris10vectorized12FunctionMathINS0_7LogImplEE33need_replace_null_data_to_defaultEv Line | Count | Source | 434 | 1 | bool need_replace_null_data_to_default() const override { | 435 | 1 | return Impl::need_replace_null_data_to_default; | 436 | 1 | } |
_ZNK5doris10vectorized12FunctionMathINS0_7PowImplEE33need_replace_null_data_to_defaultEv Line | Count | Source | 434 | 1 | bool need_replace_null_data_to_default() const override { | 435 | 1 | return Impl::need_replace_null_data_to_default; | 436 | 1 | } |
_ZNK5doris10vectorized12FunctionMathINS0_9Atan2ImplEE33need_replace_null_data_to_defaultEv Line | Count | Source | 434 | 16 | bool need_replace_null_data_to_default() const override { | 435 | 16 | return Impl::need_replace_null_data_to_default; | 436 | 16 | } |
|
437 | | |
438 | 21 | size_t get_number_of_arguments() const override { return 2; } _ZNK5doris10vectorized12FunctionMathINS0_7LogImplEE23get_number_of_argumentsEv Line | Count | Source | 438 | 1 | size_t get_number_of_arguments() const override { return 2; } |
_ZNK5doris10vectorized12FunctionMathINS0_7PowImplEE23get_number_of_argumentsEv Line | Count | Source | 438 | 1 | size_t get_number_of_arguments() const override { return 2; } |
_ZNK5doris10vectorized12FunctionMathINS0_9Atan2ImplEE23get_number_of_argumentsEv Line | Count | Source | 438 | 19 | size_t get_number_of_arguments() const override { return 2; } |
|
439 | | |
440 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
441 | 18 | uint32_t result, size_t input_rows_count) const override { |
442 | 18 | auto& column_left = block.get_by_position(arguments[0]).column; |
443 | 18 | auto& column_right = block.get_by_position(arguments[1]).column; |
444 | 18 | bool is_const_left = is_column_const(*column_left); |
445 | 18 | bool is_const_right = is_column_const(*column_right); |
446 | | |
447 | 18 | ColumnPtr column_result = nullptr; |
448 | 18 | if (is_const_left && is_const_right) { |
449 | 0 | column_result = constant_constant(column_left, column_right); |
450 | 18 | } else if (is_const_left) { |
451 | 0 | column_result = constant_vector(column_left, column_right); |
452 | 18 | } else if (is_const_right) { |
453 | 0 | column_result = vector_constant(column_left, column_right); |
454 | 18 | } else { |
455 | 18 | column_result = vector_vector(column_left, column_right); |
456 | 18 | } |
457 | 18 | block.replace_by_position(result, std::move(column_result)); |
458 | | |
459 | 18 | return Status::OK(); |
460 | 18 | } _ZNK5doris10vectorized12FunctionMathINS0_7LogImplEE12execute_implEPNS_15FunctionContextERNS0_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 441 | 1 | uint32_t result, size_t input_rows_count) const override { | 442 | 1 | auto& column_left = block.get_by_position(arguments[0]).column; | 443 | 1 | auto& column_right = block.get_by_position(arguments[1]).column; | 444 | 1 | bool is_const_left = is_column_const(*column_left); | 445 | 1 | bool is_const_right = is_column_const(*column_right); | 446 | | | 447 | 1 | ColumnPtr column_result = nullptr; | 448 | 1 | if (is_const_left && is_const_right) { | 449 | 0 | column_result = constant_constant(column_left, column_right); | 450 | 1 | } else if (is_const_left) { | 451 | 0 | column_result = constant_vector(column_left, column_right); | 452 | 1 | } else if (is_const_right) { | 453 | 0 | column_result = vector_constant(column_left, column_right); | 454 | 1 | } else { | 455 | 1 | column_result = vector_vector(column_left, column_right); | 456 | 1 | } | 457 | 1 | block.replace_by_position(result, std::move(column_result)); | 458 | | | 459 | 1 | return Status::OK(); | 460 | 1 | } |
_ZNK5doris10vectorized12FunctionMathINS0_7PowImplEE12execute_implEPNS_15FunctionContextERNS0_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 441 | 1 | uint32_t result, size_t input_rows_count) const override { | 442 | 1 | auto& column_left = block.get_by_position(arguments[0]).column; | 443 | 1 | auto& column_right = block.get_by_position(arguments[1]).column; | 444 | 1 | bool is_const_left = is_column_const(*column_left); | 445 | 1 | bool is_const_right = is_column_const(*column_right); | 446 | | | 447 | 1 | ColumnPtr column_result = nullptr; | 448 | 1 | if (is_const_left && is_const_right) { | 449 | 0 | column_result = constant_constant(column_left, column_right); | 450 | 1 | } else if (is_const_left) { | 451 | 0 | column_result = constant_vector(column_left, column_right); | 452 | 1 | } else if (is_const_right) { | 453 | 0 | column_result = vector_constant(column_left, column_right); | 454 | 1 | } else { | 455 | 1 | column_result = vector_vector(column_left, column_right); | 456 | 1 | } | 457 | 1 | block.replace_by_position(result, std::move(column_result)); | 458 | | | 459 | 1 | return Status::OK(); | 460 | 1 | } |
_ZNK5doris10vectorized12FunctionMathINS0_9Atan2ImplEE12execute_implEPNS_15FunctionContextERNS0_5BlockERKSt6vectorIjSaIjEEjm Line | Count | Source | 441 | 16 | uint32_t result, size_t input_rows_count) const override { | 442 | 16 | auto& column_left = block.get_by_position(arguments[0]).column; | 443 | 16 | auto& column_right = block.get_by_position(arguments[1]).column; | 444 | 16 | bool is_const_left = is_column_const(*column_left); | 445 | 16 | bool is_const_right = is_column_const(*column_right); | 446 | | | 447 | 16 | ColumnPtr column_result = nullptr; | 448 | 16 | if (is_const_left && is_const_right) { | 449 | 0 | column_result = constant_constant(column_left, column_right); | 450 | 16 | } else if (is_const_left) { | 451 | 0 | column_result = constant_vector(column_left, column_right); | 452 | 16 | } else if (is_const_right) { | 453 | 0 | column_result = vector_constant(column_left, column_right); | 454 | 16 | } else { | 455 | 16 | column_result = vector_vector(column_left, column_right); | 456 | 16 | } | 457 | 16 | block.replace_by_position(result, std::move(column_result)); | 458 | | | 459 | 16 | return Status::OK(); | 460 | 16 | } |
|
461 | | |
462 | | private: |
463 | 0 | ColumnPtr constant_constant(ColumnPtr column_left, ColumnPtr column_right) const { |
464 | 0 | const auto* column_left_ptr = assert_cast<const ColumnConst*>(column_left.get()); |
465 | 0 | const auto* column_right_ptr = assert_cast<const ColumnConst*>(column_right.get()); |
466 | 0 | ColumnPtr column_result = nullptr; |
467 | |
|
468 | 0 | auto res = ColumnFloat64::create(1); |
469 | 0 | if constexpr (Impl::is_nullable) { |
470 | 0 | auto null_map = ColumnUInt8::create(1, 0); |
471 | 0 | res->get_element(0) = Impl::apply(column_left_ptr->template get_value<double>(), |
472 | 0 | column_right_ptr->template get_value<double>(), |
473 | 0 | null_map->get_element(0)); |
474 | 0 | column_result = ColumnNullable::create(std::move(res), std::move(null_map)); |
475 | 0 | } else { |
476 | 0 | res->get_element(0) = Impl::apply(column_left_ptr->template get_value<double>(), |
477 | 0 | column_right_ptr->template get_value<double>()); |
478 | 0 | column_result = std::move(res); |
479 | 0 | } |
480 | |
|
481 | 0 | return ColumnConst::create(std::move(column_result), column_left->size()); |
482 | 0 | } Unexecuted instantiation: _ZNK5doris10vectorized12FunctionMathINS0_7LogImplEE17constant_constantENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ Unexecuted instantiation: _ZNK5doris10vectorized12FunctionMathINS0_7PowImplEE17constant_constantENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ Unexecuted instantiation: _ZNK5doris10vectorized12FunctionMathINS0_9Atan2ImplEE17constant_constantENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ |
483 | | |
484 | 0 | ColumnPtr vector_constant(ColumnPtr column_left, ColumnPtr column_right) const { |
485 | 0 | const auto* column_right_ptr = assert_cast<const ColumnConst*>(column_right.get()); |
486 | 0 | const auto* column_left_ptr = assert_cast<const ColumnFloat64*>(column_left.get()); |
487 | 0 | auto column_result = ColumnFloat64::create(column_left->size()); |
488 | |
|
489 | 0 | if constexpr (Impl::is_nullable) { |
490 | 0 | auto null_map = ColumnUInt8::create(column_left->size(), 0); |
491 | 0 | auto& a = column_left_ptr->get_data(); |
492 | 0 | auto& c = column_result->get_data(); |
493 | 0 | auto& n = null_map->get_data(); |
494 | 0 | size_t size = a.size(); |
495 | 0 | for (size_t i = 0; i < size; ++i) { |
496 | 0 | c[i] = Impl::apply(a[i], column_right_ptr->template get_value<double>(), n[i]); |
497 | 0 | } |
498 | 0 | return ColumnNullable::create(std::move(column_result), std::move(null_map)); |
499 | 0 | } else { |
500 | 0 | auto& a = column_left_ptr->get_data(); |
501 | 0 | auto& c = column_result->get_data(); |
502 | 0 | size_t size = a.size(); |
503 | 0 | for (size_t i = 0; i < size; ++i) { |
504 | 0 | c[i] = Impl::apply(a[i], column_right_ptr->template get_value<double>()); |
505 | 0 | } |
506 | 0 | return column_result; |
507 | 0 | } |
508 | 0 | } Unexecuted instantiation: _ZNK5doris10vectorized12FunctionMathINS0_7LogImplEE15vector_constantENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ Unexecuted instantiation: _ZNK5doris10vectorized12FunctionMathINS0_7PowImplEE15vector_constantENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ Unexecuted instantiation: _ZNK5doris10vectorized12FunctionMathINS0_9Atan2ImplEE15vector_constantENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ |
509 | | |
510 | 0 | ColumnPtr constant_vector(ColumnPtr column_left, ColumnPtr column_right) const { |
511 | 0 | const auto* column_left_ptr = assert_cast<const ColumnConst*>(column_left.get()); |
512 | |
|
513 | 0 | const auto* column_right_ptr = assert_cast<const ColumnFloat64*>(column_right.get()); |
514 | 0 | auto column_result = ColumnFloat64::create(column_right->size()); |
515 | |
|
516 | 0 | if constexpr (Impl::is_nullable) { |
517 | 0 | auto null_map = ColumnUInt8::create(column_right->size(), 0); |
518 | 0 | auto& b = column_right_ptr->get_data(); |
519 | 0 | auto& c = column_result->get_data(); |
520 | 0 | auto& n = null_map->get_data(); |
521 | 0 | size_t size = b.size(); |
522 | 0 | for (size_t i = 0; i < size; ++i) { |
523 | 0 | c[i] = Impl::apply(column_left_ptr->template get_value<double>(), b[i], n[i]); |
524 | 0 | } |
525 | 0 | return ColumnNullable::create(std::move(column_result), std::move(null_map)); |
526 | 0 | } else { |
527 | 0 | auto& b = column_right_ptr->get_data(); |
528 | 0 | auto& c = column_result->get_data(); |
529 | 0 | size_t size = b.size(); |
530 | 0 | for (size_t i = 0; i < size; ++i) { |
531 | 0 | c[i] = Impl::apply(column_left_ptr->template get_value<double>(), b[i]); |
532 | 0 | } |
533 | 0 | return column_result; |
534 | 0 | } |
535 | 0 | } Unexecuted instantiation: _ZNK5doris10vectorized12FunctionMathINS0_7LogImplEE15constant_vectorENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ Unexecuted instantiation: _ZNK5doris10vectorized12FunctionMathINS0_7PowImplEE15constant_vectorENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ Unexecuted instantiation: _ZNK5doris10vectorized12FunctionMathINS0_9Atan2ImplEE15constant_vectorENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ |
536 | | |
537 | 18 | ColumnPtr vector_vector(ColumnPtr column_left, ColumnPtr column_right) const { |
538 | 18 | const auto* column_left_ptr = |
539 | 18 | assert_cast<const ColumnFloat64*>(column_left->get_ptr().get()); |
540 | 18 | const auto* column_right_ptr = |
541 | 18 | assert_cast<const ColumnFloat64*>(column_right->get_ptr().get()); |
542 | | |
543 | 18 | auto column_result = ColumnFloat64::create(column_left->size()); |
544 | | |
545 | 18 | if constexpr (Impl::is_nullable) { |
546 | 1 | auto null_map = ColumnUInt8::create(column_result->size(), 0); |
547 | 1 | auto& a = column_left_ptr->get_data(); |
548 | 1 | auto& b = column_right_ptr->get_data(); |
549 | 1 | auto& c = column_result->get_data(); |
550 | 1 | auto& n = null_map->get_data(); |
551 | 1 | size_t size = a.size(); |
552 | 7 | for (size_t i = 0; i < size; ++i) { |
553 | 6 | c[i] = Impl::apply(a[i], b[i], n[i]); |
554 | 6 | } |
555 | 1 | return ColumnNullable::create(std::move(column_result), std::move(null_map)); |
556 | 17 | } else { |
557 | 17 | auto& a = column_left_ptr->get_data(); |
558 | 17 | auto& b = column_right_ptr->get_data(); |
559 | 17 | auto& c = column_result->get_data(); |
560 | 17 | size_t size = a.size(); |
561 | 42 | for (size_t i = 0; i < size; ++i) { |
562 | 25 | c[i] = Impl::apply(a[i], b[i]); |
563 | 25 | } |
564 | 17 | return column_result; |
565 | 17 | } |
566 | 18 | } _ZNK5doris10vectorized12FunctionMathINS0_7LogImplEE13vector_vectorENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ Line | Count | Source | 537 | 1 | ColumnPtr vector_vector(ColumnPtr column_left, ColumnPtr column_right) const { | 538 | 1 | const auto* column_left_ptr = | 539 | 1 | assert_cast<const ColumnFloat64*>(column_left->get_ptr().get()); | 540 | 1 | const auto* column_right_ptr = | 541 | 1 | assert_cast<const ColumnFloat64*>(column_right->get_ptr().get()); | 542 | | | 543 | 1 | auto column_result = ColumnFloat64::create(column_left->size()); | 544 | | | 545 | 1 | if constexpr (Impl::is_nullable) { | 546 | 1 | auto null_map = ColumnUInt8::create(column_result->size(), 0); | 547 | 1 | auto& a = column_left_ptr->get_data(); | 548 | 1 | auto& b = column_right_ptr->get_data(); | 549 | 1 | auto& c = column_result->get_data(); | 550 | 1 | auto& n = null_map->get_data(); | 551 | 1 | size_t size = a.size(); | 552 | 7 | for (size_t i = 0; i < size; ++i) { | 553 | 6 | c[i] = Impl::apply(a[i], b[i], n[i]); | 554 | 6 | } | 555 | 1 | return ColumnNullable::create(std::move(column_result), std::move(null_map)); | 556 | | } else { | 557 | | auto& a = column_left_ptr->get_data(); | 558 | | auto& b = column_right_ptr->get_data(); | 559 | | auto& c = column_result->get_data(); | 560 | | size_t size = a.size(); | 561 | | for (size_t i = 0; i < size; ++i) { | 562 | | c[i] = Impl::apply(a[i], b[i]); | 563 | | } | 564 | | return column_result; | 565 | | } | 566 | 1 | } |
_ZNK5doris10vectorized12FunctionMathINS0_7PowImplEE13vector_vectorENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ Line | Count | Source | 537 | 1 | ColumnPtr vector_vector(ColumnPtr column_left, ColumnPtr column_right) const { | 538 | 1 | const auto* column_left_ptr = | 539 | 1 | assert_cast<const ColumnFloat64*>(column_left->get_ptr().get()); | 540 | 1 | const auto* column_right_ptr = | 541 | 1 | assert_cast<const ColumnFloat64*>(column_right->get_ptr().get()); | 542 | | | 543 | 1 | auto column_result = ColumnFloat64::create(column_left->size()); | 544 | | | 545 | | if constexpr (Impl::is_nullable) { | 546 | | auto null_map = ColumnUInt8::create(column_result->size(), 0); | 547 | | auto& a = column_left_ptr->get_data(); | 548 | | auto& b = column_right_ptr->get_data(); | 549 | | auto& c = column_result->get_data(); | 550 | | auto& n = null_map->get_data(); | 551 | | size_t size = a.size(); | 552 | | for (size_t i = 0; i < size; ++i) { | 553 | | c[i] = Impl::apply(a[i], b[i], n[i]); | 554 | | } | 555 | | return ColumnNullable::create(std::move(column_result), std::move(null_map)); | 556 | 1 | } else { | 557 | 1 | auto& a = column_left_ptr->get_data(); | 558 | 1 | auto& b = column_right_ptr->get_data(); | 559 | 1 | auto& c = column_result->get_data(); | 560 | 1 | size_t size = a.size(); | 561 | 5 | for (size_t i = 0; i < size; ++i) { | 562 | 4 | c[i] = Impl::apply(a[i], b[i]); | 563 | 4 | } | 564 | 1 | return column_result; | 565 | 1 | } | 566 | 1 | } |
_ZNK5doris10vectorized12FunctionMathINS0_9Atan2ImplEE13vector_vectorENS_3COWINS0_7IColumnEE13immutable_ptrIS5_EES8_ Line | Count | Source | 537 | 16 | ColumnPtr vector_vector(ColumnPtr column_left, ColumnPtr column_right) const { | 538 | 16 | const auto* column_left_ptr = | 539 | 16 | assert_cast<const ColumnFloat64*>(column_left->get_ptr().get()); | 540 | 16 | const auto* column_right_ptr = | 541 | 16 | assert_cast<const ColumnFloat64*>(column_right->get_ptr().get()); | 542 | | | 543 | 16 | auto column_result = ColumnFloat64::create(column_left->size()); | 544 | | | 545 | | if constexpr (Impl::is_nullable) { | 546 | | auto null_map = ColumnUInt8::create(column_result->size(), 0); | 547 | | auto& a = column_left_ptr->get_data(); | 548 | | auto& b = column_right_ptr->get_data(); | 549 | | auto& c = column_result->get_data(); | 550 | | auto& n = null_map->get_data(); | 551 | | size_t size = a.size(); | 552 | | for (size_t i = 0; i < size; ++i) { | 553 | | c[i] = Impl::apply(a[i], b[i], n[i]); | 554 | | } | 555 | | return ColumnNullable::create(std::move(column_result), std::move(null_map)); | 556 | 16 | } else { | 557 | 16 | auto& a = column_left_ptr->get_data(); | 558 | 16 | auto& b = column_right_ptr->get_data(); | 559 | 16 | auto& c = column_result->get_data(); | 560 | 16 | size_t size = a.size(); | 561 | 37 | for (size_t i = 0; i < size; ++i) { | 562 | 21 | c[i] = Impl::apply(a[i], b[i]); | 563 | 21 | } | 564 | 16 | return column_result; | 565 | 16 | } | 566 | 16 | } |
|
567 | | }; |
568 | | |
569 | | class FunctionNormalCdf : public IFunction { |
570 | | public: |
571 | | static constexpr auto name = "normal_cdf"; |
572 | | |
573 | 1 | String get_name() const override { return name; } |
574 | | |
575 | 2 | static FunctionPtr create() { return std::make_shared<FunctionNormalCdf>(); } |
576 | | |
577 | 0 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
578 | 0 | return make_nullable(std::make_shared<DataTypeFloat64>()); |
579 | 0 | } |
580 | | |
581 | 1 | DataTypes get_variadic_argument_types_impl() const override { |
582 | 1 | return {std::make_shared<DataTypeFloat64>(), std::make_shared<DataTypeFloat64>(), |
583 | 1 | std::make_shared<DataTypeFloat64>()}; |
584 | 1 | } |
585 | 0 | size_t get_number_of_arguments() const override { return 3; } |
586 | | |
587 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
588 | 0 | uint32_t result, size_t input_rows_count) const override { |
589 | 0 | auto result_column = ColumnFloat64::create(input_rows_count); |
590 | 0 | auto result_null_map_column = ColumnUInt8::create(input_rows_count, 0); |
591 | |
|
592 | 0 | auto& result_data = result_column->get_data(); |
593 | 0 | NullMap& result_null_map = |
594 | 0 | assert_cast<ColumnUInt8*>(result_null_map_column.get())->get_data(); |
595 | |
|
596 | 0 | ColumnPtr argument_columns[3]; |
597 | 0 | bool col_const[3]; |
598 | 0 | size_t argument_size = arguments.size(); |
599 | 0 | for (int i = 0; i < argument_size; ++i) { |
600 | 0 | argument_columns[i] = block.get_by_position(arguments[i]).column; |
601 | 0 | col_const[i] = is_column_const(*argument_columns[i]); |
602 | 0 | if (col_const[i]) { |
603 | 0 | argument_columns[i] = |
604 | 0 | static_cast<const ColumnConst&>(*argument_columns[i]).get_data_column_ptr(); |
605 | 0 | } |
606 | 0 | } |
607 | |
|
608 | 0 | auto* mean_col = assert_cast<const ColumnFloat64*>(argument_columns[0].get()); |
609 | 0 | auto* sd_col = assert_cast<const ColumnFloat64*>(argument_columns[1].get()); |
610 | 0 | auto* value_col = assert_cast<const ColumnFloat64*>(argument_columns[2].get()); |
611 | |
|
612 | 0 | result_column->reserve(input_rows_count); |
613 | 0 | for (size_t i = 0; i < input_rows_count; ++i) { |
614 | 0 | double mean = mean_col->get_element(index_check_const(i, col_const[0])); |
615 | 0 | double sd = sd_col->get_element(index_check_const(i, col_const[1])); |
616 | 0 | double v = value_col->get_element(index_check_const(i, col_const[2])); |
617 | |
|
618 | 0 | if (!check_argument(sd)) [[unlikely]] { |
619 | 0 | result_null_map[i] = true; |
620 | 0 | continue; |
621 | 0 | } |
622 | 0 | result_data[i] = calculate_cell(mean, sd, v); |
623 | 0 | } |
624 | |
|
625 | 0 | block.get_by_position(result).column = |
626 | 0 | ColumnNullable::create(std::move(result_column), std::move(result_null_map_column)); |
627 | 0 | return Status::OK(); |
628 | 0 | } |
629 | | |
630 | 0 | static bool check_argument(double sd) { return sd > 0; } |
631 | 0 | static double calculate_cell(double mean, double sd, double v) { |
632 | | #ifdef __APPLE__ |
633 | | const double sqrt2 = std::sqrt(2); |
634 | | #else |
635 | 0 | constexpr double sqrt2 = std::numbers::sqrt2; |
636 | 0 | #endif |
637 | |
|
638 | 0 | return 0.5 * (std::erf((v - mean) / (sd * sqrt2)) + 1); |
639 | 0 | } |
640 | | }; |
641 | | |
642 | | // TODO: Now math may cause one thread compile time too long, because the function in math |
643 | | // so mush. Split it to speed up compile time in the future |
644 | 1 | void register_function_math(SimpleFunctionFactory& factory) { |
645 | 1 | factory.register_function<FunctionAcos>(); |
646 | 1 | factory.register_function<FunctionAcosh>(); |
647 | 1 | factory.register_function<FunctionAsin>(); |
648 | 1 | factory.register_function<FunctionAsinh>(); |
649 | 1 | factory.register_function<FunctionAtan>(); |
650 | 1 | factory.register_function<FunctionAtanh>(); |
651 | 1 | factory.register_function<FunctionMath<LogImpl>>(); |
652 | 1 | factory.register_function<FunctionMath<PowImpl>>(); |
653 | 1 | factory.register_function<FunctionMath<Atan2Impl>>(); |
654 | 1 | factory.register_function<FunctionCos>(); |
655 | 1 | factory.register_function<FunctionCosh>(); |
656 | 1 | factory.register_function<FunctionE>(); |
657 | 1 | factory.register_alias("ln", "dlog1"); |
658 | 1 | factory.register_function<FunctionMathLog<ImplLn>>(); |
659 | 1 | factory.register_function<FunctionMathLog<ImplLog2>>(); |
660 | 1 | factory.register_function<FunctionMathLog<ImplLog10>>(); |
661 | 1 | factory.register_alias("log10", "dlog10"); |
662 | 1 | factory.register_function<FunctionPi>(); |
663 | 1 | factory.register_function<FunctionSign>(); |
664 | 1 | factory.register_function<FunctionAbs>(); |
665 | 1 | factory.register_function<FunctionNegative>(); |
666 | 1 | factory.register_function<FunctionPositive>(); |
667 | 1 | factory.register_function<FunctionSin>(); |
668 | 1 | factory.register_function<FunctionSinh>(); |
669 | 1 | factory.register_function<FunctionSqrt>(); |
670 | 1 | factory.register_alias("sqrt", "dsqrt"); |
671 | 1 | factory.register_function<FunctionCbrt>(); |
672 | 1 | factory.register_function<FunctionTan>(); |
673 | 1 | factory.register_function<FunctionTanh>(); |
674 | 1 | factory.register_function<FunctionCot>(); |
675 | 1 | factory.register_function<FunctionSec>(); |
676 | 1 | factory.register_function<FunctionCosec>(); |
677 | 1 | factory.register_alias("pow", "power"); |
678 | 1 | factory.register_alias("pow", "dpow"); |
679 | 1 | factory.register_alias("pow", "fpow"); |
680 | 1 | factory.register_function<FunctionExp>(); |
681 | 1 | factory.register_alias("exp", "dexp"); |
682 | 1 | factory.register_function<FunctionRadians>(); |
683 | 1 | factory.register_function<FunctionDegrees>(); |
684 | 1 | factory.register_function<FunctionBin>(); |
685 | 1 | factory.register_function<FunctionNormalCdf>(); |
686 | 1 | } |
687 | | } // namespace doris::vectorized |