be/src/exprs/function/function.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 | | // This file is copied from |
18 | | // https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/IFunction.h |
19 | | // and modified by Doris |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include <fmt/format.h> |
24 | | #include <glog/logging.h> |
25 | | |
26 | | #include <cstddef> |
27 | | #include <memory> |
28 | | #include <string> |
29 | | #include <utility> |
30 | | |
31 | | #include "common/exception.h" |
32 | | #include "common/logging.h" |
33 | | #include "common/status.h" |
34 | | #include "core/block/block.h" |
35 | | #include "core/block/column_numbers.h" |
36 | | #include "core/block/column_with_type_and_name.h" |
37 | | #include "core/block/columns_with_type_and_name.h" |
38 | | #include "core/data_type/data_type.h" |
39 | | #include "core/data_type/data_type_array.h" |
40 | | #include "core/data_type/data_type_map.h" |
41 | | #include "core/data_type/data_type_nullable.h" |
42 | | #include "core/data_type/data_type_struct.h" |
43 | | #include "core/data_type/define_primitive_type.h" |
44 | | #include "core/types.h" |
45 | | #include "exprs/function_context.h" |
46 | | #include "exprs/vexpr_fwd.h" |
47 | | #include "storage/index/inverted/inverted_index_iterator.h" // IWYU pragma: keep |
48 | | #include "storage/index/inverted/inverted_index_parser.h" |
49 | | #include "storage/index/zone_map/zonemap_filter_result.h" |
50 | | |
51 | | namespace doris { |
52 | | struct InvertedIndexAnalyzerCtx; |
53 | | } // namespace doris |
54 | | |
55 | | namespace doris { |
56 | | |
57 | | struct FunctionAttr { |
58 | | bool new_version_unix_timestamp {false}; |
59 | | }; |
60 | | |
61 | | #define RETURN_REAL_TYPE_FOR_DATEV2_FUNCTION(TYPE) \ |
62 | 1.90k | bool is_nullable = false; \ |
63 | 1.90k | bool is_datev2 = false; \ |
64 | 3.53k | for (auto it : arguments) { \ |
65 | 3.53k | is_nullable = is_nullable || it.type->is_nullable(); \ |
66 | 3.53k | is_datev2 = is_datev2 || it.type->get_primitive_type() == TYPE_DATEV2 || \ |
67 | 3.53k | it.type->get_primitive_type() == TYPE_DATETIMEV2; \ |
68 | 3.53k | } \ |
69 | 1.90k | return is_nullable || !is_datev2 \ |
70 | 1.90k | ? make_nullable( \ |
71 | 1.54k | std::make_shared<typename PrimitiveTypeTraits<TYPE>::DataType>()) \ |
72 | 1.90k | : std::make_shared<typename PrimitiveTypeTraits<TYPE>::DataType>(); |
73 | | |
74 | | #define SET_NULLMAP_IF_FALSE(EXPR) \ |
75 | | if (!EXPR) [[unlikely]] { \ |
76 | | null_map[i] = true; \ |
77 | | } |
78 | | |
79 | | class Field; |
80 | | class VExpr; |
81 | | class ZoneMapEvalContext; |
82 | | |
83 | | // Only use dispose the variadic argument |
84 | | template <typename T> |
85 | | auto has_variadic_argument_types(T&& arg) -> decltype(T::get_variadic_argument_types()) {}; |
86 | | void has_variadic_argument_types(...); |
87 | | |
88 | | template <typename T> |
89 | | concept HasGetVariadicArgumentTypesImpl = requires(T t) { |
90 | | { t.get_variadic_argument_types_impl() } -> std::same_as<DataTypes>; |
91 | | }; |
92 | | |
93 | | bool have_null_column(const Block& block, const ColumnNumbers& args); |
94 | | bool have_null_column(const ColumnsWithTypeAndName& args); |
95 | | |
96 | | /// The simplest executable object. |
97 | | /// Motivation: |
98 | | /// * Prepare something heavy once before main execution loop instead of doing it for each block. |
99 | | /// * Provide const interface for IFunctionBase (later). |
100 | | class IPreparedFunction { |
101 | | public: |
102 | 1.91M | virtual ~IPreparedFunction() = default; |
103 | | |
104 | | /// Get the main function name. |
105 | | virtual String get_name() const = 0; |
106 | | |
107 | | virtual Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
108 | | uint32_t result, size_t input_rows_count) const = 0; |
109 | | }; |
110 | | |
111 | | using PreparedFunctionPtr = std::shared_ptr<IPreparedFunction>; |
112 | | |
113 | | class PreparedFunctionImpl : public IPreparedFunction { |
114 | | public: |
115 | | Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
116 | | uint32_t result, size_t input_rows_count) const final; |
117 | | |
118 | | /** If the function have non-zero number of arguments, |
119 | | * and if all arguments are constant, that we could automatically provide default implementation: |
120 | | * arguments are converted to ordinary columns with single value which is not const, then function is executed as usual, |
121 | | * and then the result is converted to constant column. |
122 | | */ |
123 | 3.05M | virtual bool use_default_implementation_for_constants() const { return true; } |
124 | | |
125 | | /** If use_default_implementation_for_nulls() is true, after execute the function, |
126 | | * whether need to replace the nested data of null data to the default value. |
127 | | * E.g. for binary arithmetic exprs, need return true to avoid false overflow. |
128 | | */ |
129 | 0 | virtual bool need_replace_null_data_to_default() const { return false; } |
130 | | |
131 | | protected: |
132 | | virtual Status execute_impl(FunctionContext* context, Block& block, |
133 | | const ColumnNumbers& arguments, uint32_t result, |
134 | | size_t input_rows_count) const = 0; |
135 | | |
136 | | /** Default implementation in presence of Nullable arguments or NULL constants as arguments is the following: |
137 | | * if some of arguments are NULL constants then return NULL constant, |
138 | | * if some of arguments are Nullable, then execute function as usual for block, |
139 | | * where Nullable columns are substituted with nested columns (they have arbitrary values in rows corresponding to NULL value) |
140 | | * and wrap result in Nullable column where NULLs are in all rows where any of arguments are NULL. |
141 | | */ |
142 | 0 | virtual bool use_default_implementation_for_nulls() const { return true; } |
143 | | |
144 | 0 | virtual bool skip_return_type_check() const { return false; } |
145 | | |
146 | | /** Some arguments could remain constant during this implementation. |
147 | | * Every argument required const must write here and no checks elsewhere. |
148 | | */ |
149 | 2.75k | virtual ColumnNumbers get_arguments_that_are_always_constant() const { return {}; } |
150 | | |
151 | | private: |
152 | | Status default_implementation_for_nulls(FunctionContext* context, Block& block, |
153 | | const ColumnNumbers& args, uint32_t result, |
154 | | size_t input_rows_count, bool* executed) const; |
155 | | Status default_implementation_for_constant_arguments(FunctionContext* context, Block& block, |
156 | | const ColumnNumbers& args, uint32_t result, |
157 | | size_t input_rows_count, |
158 | | bool* executed) const; |
159 | | Status default_execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
160 | | uint32_t result, size_t input_rows_count) const; |
161 | | Status _execute_skipped_constant_deal(FunctionContext* context, Block& block, |
162 | | const ColumnNumbers& args, uint32_t result, |
163 | | size_t input_rows_count) const; |
164 | | }; |
165 | | |
166 | | /// Function with known arguments and return type. |
167 | | class IFunctionBase { |
168 | | public: |
169 | 2.30M | virtual ~IFunctionBase() = default; |
170 | | |
171 | | /// Get the main function name. |
172 | | virtual String get_name() const = 0; |
173 | | |
174 | | virtual const DataTypes& get_argument_types() const = 0; |
175 | | virtual const DataTypePtr& get_return_type() const = 0; |
176 | | |
177 | 2.34k | virtual double execute_cost() const { return 1.0; } |
178 | | |
179 | | /// Do preparations and return executable. |
180 | | /// sample_block should contain data types of arguments and values of constants, if relevant. |
181 | | virtual PreparedFunctionPtr prepare(FunctionContext* context, const Block& sample_block, |
182 | | const ColumnNumbers& arguments, uint32_t result) const = 0; |
183 | | |
184 | | /// Override this when function need to store state in the `FunctionContext`, or do some |
185 | | /// preparation work according to information from `FunctionContext`. |
186 | 512k | virtual Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) { |
187 | 512k | return Status::OK(); |
188 | 512k | } |
189 | | |
190 | | Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
191 | 1.80M | uint32_t result, size_t input_rows_count) const { |
192 | | // Some function implementations may not handle the case where input_rows_count is 0 |
193 | | // (e.g., some functions access the 0th row of input columns during execution). |
194 | | // Additionally, some UDF functions may hang if they write 0 rows and then try to read. |
195 | | // Therefore, before executing the function, we first check if input_rows_count is 0. |
196 | | // If it is 0, we directly return an empty result column to avoid executing the function body. |
197 | 1.80M | if (input_rows_count == 0) { |
198 | 318 | block.get_by_position(result).column = |
199 | 318 | block.get_by_position(result).type->create_column(); |
200 | 318 | return Status::OK(); |
201 | 318 | } |
202 | 1.80M | try { |
203 | 1.80M | return prepare(context, block, arguments, result) |
204 | 1.80M | ->execute(context, block, arguments, result, input_rows_count); |
205 | 1.80M | } catch (const Exception& e) { |
206 | 314 | return e.to_status(); |
207 | 314 | } |
208 | 1.80M | } |
209 | | |
210 | | virtual Status evaluate_inverted_index( |
211 | | const ColumnsWithTypeAndName& arguments, |
212 | | const std::vector<IndexFieldNameAndTypePair>& data_type_with_names, |
213 | | std::vector<segment_v2::IndexIterator*> iterators, uint32_t num_rows, |
214 | | const InvertedIndexAnalyzerCtx* analyzer_ctx, |
215 | 44 | segment_v2::InvertedIndexResultBitmap& bitmap_result) const { |
216 | 44 | return Status::OK(); |
217 | 44 | } |
218 | | |
219 | | /// Do cleaning work when function is finished, i.e., release state variables in the |
220 | | /// `FunctionContext` which are registered in `prepare` phase. |
221 | 2.35M | virtual Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) { |
222 | 2.35M | return Status::OK(); |
223 | 2.35M | } |
224 | | |
225 | | virtual bool is_use_default_implementation_for_constants() const = 0; |
226 | | |
227 | 0 | virtual bool is_udf_function() const { return false; } |
228 | | |
229 | 2.15k | virtual bool can_push_down_to_index() const { return false; } |
230 | | |
231 | 491k | virtual bool is_blockable() const { return false; } |
232 | | |
233 | | virtual ZoneMapFilterResult evaluate_zonemap_filter( |
234 | 2.53k | const ZoneMapEvalContext& ctx, const VExprSPtrs& function_arguments) const { |
235 | 2.53k | return ZoneMapFilterResult::kUnsupported; |
236 | 2.53k | } |
237 | | |
238 | 3.31k | virtual bool can_evaluate_zonemap_filter(const VExprSPtrs& /*function_arguments*/) const { |
239 | 3.31k | return false; |
240 | 3.31k | } |
241 | | }; |
242 | | |
243 | | using FunctionBasePtr = std::shared_ptr<IFunctionBase>; |
244 | | |
245 | | /// Creates IFunctionBase from argument types list. |
246 | | class IFunctionBuilder { |
247 | | public: |
248 | 2.31M | virtual ~IFunctionBuilder() = default; |
249 | | |
250 | | /// Get the main function name. |
251 | | virtual String get_name() const = 0; |
252 | | |
253 | | /// Override and return true if function could take different number of arguments. |
254 | | ///TODO: this function is not actually used now. but in check_number_of_arguments we still need it because for many |
255 | | /// functions we didn't set the correct number of arguments. |
256 | | virtual bool is_variadic() const = 0; |
257 | | |
258 | | /// For non-variadic functions, return number of arguments; otherwise return zero (that should be ignored). |
259 | | virtual size_t get_number_of_arguments() const = 0; |
260 | | |
261 | | /// Throw if number of arguments is incorrect. Default implementation will check only in non-variadic case. |
262 | | virtual void check_number_of_arguments(size_t number_of_arguments) const = 0; |
263 | | |
264 | | /// Check arguments and return IFunctionBase. |
265 | | virtual FunctionBasePtr build(const ColumnsWithTypeAndName& arguments, |
266 | | const DataTypePtr& return_type) const = 0; |
267 | | |
268 | | /// For higher-order functions (functions, that have lambda expression as at least one argument). |
269 | | /// You pass data types with empty DataTypeFunction for lambda arguments. |
270 | | /// This function will replace it with DataTypeFunction containing actual types. |
271 | | virtual DataTypes get_variadic_argument_types() const = 0; |
272 | | |
273 | | /// Returns indexes of arguments, that must be ColumnConst |
274 | | virtual ColumnNumbers get_arguments_that_are_always_constant() const = 0; |
275 | | }; |
276 | | |
277 | | using FunctionBuilderPtr = std::shared_ptr<IFunctionBuilder>; |
278 | | |
279 | 3 | inline std::string get_types_string(const ColumnsWithTypeAndName& arguments) { |
280 | 3 | std::string types; |
281 | 3 | for (const auto& argument : arguments) { |
282 | 2 | if (!types.empty()) { |
283 | 1 | types += ", "; |
284 | 1 | } |
285 | 2 | types += argument.type->get_name(); |
286 | 2 | } |
287 | 3 | return types; |
288 | 3 | } |
289 | | |
290 | | /// used in function_factory. when we register a function, save a builder. to get a function, to get a builder. |
291 | | /// will use DefaultFunctionBuilder as the default builder in function's registration if we didn't explicitly specify. |
292 | | class FunctionBuilderImpl : public IFunctionBuilder { |
293 | | public: |
294 | | FunctionBasePtr build(const ColumnsWithTypeAndName& arguments, |
295 | 1.81M | const DataTypePtr& return_type) const final { |
296 | 1.81M | if (skip_return_type_check()) { |
297 | 1.33M | return build_impl(arguments, return_type); |
298 | 1.33M | } |
299 | 479k | const DataTypePtr& func_return_type = get_return_type(arguments); |
300 | 479k | if (func_return_type == nullptr) { |
301 | 1 | throw doris::Exception( |
302 | 1 | ErrorCode::INTERNAL_ERROR, |
303 | 1 | "function return type check failed, function_name={}, " |
304 | 1 | "expect_return_type={}, real_return_type is nullptr, input_arguments={}", |
305 | 1 | get_name(), return_type->get_name(), get_types_string(arguments)); |
306 | 1 | } |
307 | | |
308 | | // check return types equal. |
309 | 479k | if (!(return_type->equals(*func_return_type) || |
310 | | // For null constant argument, `get_return_type` would return |
311 | | // Nullable<DataTypeNothing> when `use_default_implementation_for_nulls` is true. |
312 | 479k | (return_type->is_nullable() && func_return_type->is_nullable() && |
313 | 2.54k | ((DataTypeNullable*)func_return_type.get()) |
314 | 1.43k | ->get_nested_type() |
315 | 1.43k | ->get_primitive_type() == INVALID_TYPE) || |
316 | 479k | is_date_or_datetime_or_decimal(return_type, func_return_type) || |
317 | 479k | is_nested_type_date_or_datetime_or_decimal(return_type, func_return_type))) { |
318 | 2 | throw doris::Exception( |
319 | 2 | ErrorCode::INTERNAL_ERROR, |
320 | 2 | "function return type check failed, function_name={}, " |
321 | 2 | "fe plan return type={}, be real return type={}, input_arguments={}", |
322 | 2 | get_name(), return_type->get_name(), func_return_type->get_name(), |
323 | 2 | get_types_string(arguments)); |
324 | 2 | } |
325 | 479k | return build_impl(arguments, return_type); |
326 | 479k | } |
327 | | |
328 | 404k | bool is_variadic() const override { return false; } |
329 | | |
330 | | // Default implementation. Will check only in non-variadic case. |
331 | | void check_number_of_arguments(size_t number_of_arguments) const override; |
332 | | // the return type should be same with what FE plans. |
333 | | // it returns: `get_return_type_impl` if `use_default_implementation_for_nulls` = false |
334 | | // `get_return_type_impl` warpped in NULL if `use_default_implementation_for_nulls` = true and input has NULL |
335 | | DataTypePtr get_return_type(const ColumnsWithTypeAndName& arguments) const; |
336 | | |
337 | 9.53k | DataTypes get_variadic_argument_types() const override { |
338 | 9.53k | return get_variadic_argument_types_impl(); |
339 | 9.53k | } |
340 | | |
341 | 0 | ColumnNumbers get_arguments_that_are_always_constant() const override { return {}; } |
342 | | |
343 | | protected: |
344 | | // Get the result type by argument type. If the function does not apply to these arguments, throw an exception. |
345 | | // the get_return_type_impl and its overrides should only return the nested type if `use_default_implementation_for_nulls` is true. |
346 | | // whether to wrap in nullable type will be automatically decided. |
347 | 474k | virtual DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const { |
348 | 474k | DataTypes data_types(arguments.size()); |
349 | 1.39M | for (size_t i = 0; i < arguments.size(); ++i) { |
350 | 924k | data_types[i] = arguments[i].type; |
351 | 924k | } |
352 | 474k | return get_return_type_impl(data_types); |
353 | 474k | } |
354 | | |
355 | 0 | virtual DataTypePtr get_return_type_impl(const DataTypes& /*arguments*/) const { |
356 | 0 | throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, |
357 | 0 | "get_return_type is not implemented for {}", get_name()); |
358 | 0 | return nullptr; |
359 | 0 | } |
360 | | |
361 | | /** If use_default_implementation_for_nulls() is true, than change arguments for get_return_type() and build_impl(): |
362 | | * if some of arguments are Nullable(Nothing) then don't call get_return_type(), call build_impl() with return_type = Nullable(Nothing), |
363 | | * if some of arguments are Nullable, then: |
364 | | * - Nullable types are substituted with nested types for get_return_type() function |
365 | | * - WRAP get_return_type() RESULT IN NULLABLE type and pass to build_impl |
366 | | * |
367 | | * Otherwise build returns build_impl(arguments, get_return_type(arguments)); |
368 | | */ |
369 | 0 | virtual bool use_default_implementation_for_nulls() const { return true; } |
370 | | |
371 | 16 | virtual bool skip_return_type_check() const { return false; } |
372 | | |
373 | 0 | virtual bool need_replace_null_data_to_default() const { return false; } |
374 | | |
375 | | /// return a real function object to execute. called in build(...). |
376 | | virtual FunctionBasePtr build_impl(const ColumnsWithTypeAndName& arguments, |
377 | | const DataTypePtr& return_type) const = 0; |
378 | | |
379 | 2.86k | virtual DataTypes get_variadic_argument_types_impl() const { return {}; } |
380 | | |
381 | | private: |
382 | | bool is_date_or_datetime_or_decimal(const DataTypePtr& return_type, |
383 | | const DataTypePtr& func_return_type) const; |
384 | | bool is_nested_type_date_or_datetime_or_decimal(const DataTypePtr& return_type, |
385 | | const DataTypePtr& func_return_type) const; |
386 | | }; |
387 | | |
388 | | /// Previous function interface. |
389 | | class IFunction : public std::enable_shared_from_this<IFunction>, |
390 | | public FunctionBuilderImpl, |
391 | | public IFunctionBase, |
392 | | public PreparedFunctionImpl { |
393 | | public: |
394 | | String get_name() const override = 0; |
395 | | |
396 | | /// Notice: We should not change the column in the block, because the column may be shared by multiple expressions or exec nodes. |
397 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
398 | | uint32_t result, size_t input_rows_count) const override = 0; |
399 | | |
400 | | /// Override this functions to change default implementation behavior. See details in IMyFunction. |
401 | 878k | bool use_default_implementation_for_nulls() const override { return true; } |
402 | | |
403 | 479k | bool skip_return_type_check() const override { return false; } |
404 | | |
405 | 164k | bool need_replace_null_data_to_default() const override { return false; } |
406 | | |
407 | | /// all constancy check should use this function to do automatically |
408 | 562k | ColumnNumbers get_arguments_that_are_always_constant() const override { return {}; } |
409 | | |
410 | 1.34M | bool is_use_default_implementation_for_constants() const override { |
411 | 1.34M | return use_default_implementation_for_constants(); |
412 | 1.34M | } |
413 | | |
414 | | using PreparedFunctionImpl::execute; |
415 | | using FunctionBuilderImpl::get_return_type_impl; |
416 | | using FunctionBuilderImpl::get_variadic_argument_types_impl; |
417 | | using FunctionBuilderImpl::get_return_type; |
418 | | |
419 | | [[noreturn]] PreparedFunctionPtr prepare(FunctionContext* context, |
420 | | const Block& /*sample_block*/, |
421 | | const ColumnNumbers& /*arguments*/, |
422 | 0 | uint32_t /*result*/) const final { |
423 | 0 | throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, |
424 | 0 | "prepare is not implemented for IFunction {}", get_name()); |
425 | 0 | __builtin_unreachable(); |
426 | 0 | } |
427 | | |
428 | 1.78M | Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { |
429 | 1.78M | return Status::OK(); |
430 | 1.78M | } |
431 | | |
432 | 0 | [[noreturn]] const DataTypes& get_argument_types() const final { |
433 | 0 | throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, |
434 | 0 | "get_argument_types is not implemented for IFunction {}", |
435 | 0 | get_name()); |
436 | 0 | __builtin_unreachable(); |
437 | 0 | } |
438 | | |
439 | 0 | [[noreturn]] const DataTypePtr& get_return_type() const final { |
440 | 0 | throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, |
441 | 0 | "get_return_type is not implemented for IFunction {}", get_name()); |
442 | 0 | __builtin_unreachable(); |
443 | 0 | } |
444 | | |
445 | | protected: |
446 | | FunctionBasePtr build_impl(const ColumnsWithTypeAndName& /*arguments*/, |
447 | 0 | const DataTypePtr& /*return_type*/) const final { |
448 | 0 | throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, |
449 | 0 | "build_impl is not implemented for IFunction {}", get_name()); |
450 | 0 | __builtin_unreachable(); |
451 | 0 | return {}; |
452 | 0 | } |
453 | | }; |
454 | | |
455 | | /* |
456 | | * when we register a function which didn't specify its base(i.e. inherited from IFunction), actually we use this as a wrapper. |
457 | | * it saves real implementation as `function`. |
458 | | */ |
459 | | class DefaultFunction final : public IFunctionBase { |
460 | | public: |
461 | | DefaultFunction(std::shared_ptr<IFunction> function_, DataTypes arguments_, |
462 | | DataTypePtr return_type_) |
463 | 481k | : function(std::move(function_)), |
464 | 481k | arguments(std::move(arguments_)), |
465 | 481k | return_type(std::move(return_type_)) {} |
466 | | |
467 | 328 | String get_name() const override { return function->get_name(); } |
468 | | |
469 | 0 | const DataTypes& get_argument_types() const override { return arguments; } |
470 | 1 | const DataTypePtr& get_return_type() const override { return return_type; } |
471 | | |
472 | | // return a default wrapper for IFunction. |
473 | | PreparedFunctionPtr prepare(FunctionContext* context, const Block& /*sample_block*/, |
474 | | const ColumnNumbers& /*arguments*/, |
475 | 385k | uint32_t /*result*/) const override { |
476 | 385k | return function; |
477 | 385k | } |
478 | | |
479 | 652k | double execute_cost() const override { return function->execute_cost(); } |
480 | | |
481 | 1.88M | Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { |
482 | 1.88M | return function->open(context, scope); |
483 | 1.88M | } |
484 | | |
485 | 1.89M | Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { |
486 | 1.89M | return function->close(context, scope); |
487 | 1.89M | } |
488 | | |
489 | | Status evaluate_inverted_index( |
490 | | const ColumnsWithTypeAndName& args, |
491 | | const std::vector<IndexFieldNameAndTypePair>& data_type_with_names, |
492 | | std::vector<segment_v2::IndexIterator*> iterators, uint32_t num_rows, |
493 | | const InvertedIndexAnalyzerCtx* analyzer_ctx, |
494 | 9.43k | segment_v2::InvertedIndexResultBitmap& bitmap_result) const override { |
495 | 9.43k | return function->evaluate_inverted_index(args, data_type_with_names, iterators, num_rows, |
496 | 9.43k | analyzer_ctx, bitmap_result); |
497 | 9.43k | } |
498 | | |
499 | 1.34M | bool is_use_default_implementation_for_constants() const override { |
500 | 1.34M | return function->is_use_default_implementation_for_constants(); |
501 | 1.34M | } |
502 | | |
503 | 2.14k | bool can_push_down_to_index() const override { return function->can_push_down_to_index(); } |
504 | | |
505 | 490k | bool is_blockable() const override { return function->is_blockable(); } |
506 | | |
507 | | ZoneMapFilterResult evaluate_zonemap_filter( |
508 | 15.1k | const ZoneMapEvalContext& ctx, const VExprSPtrs& function_arguments) const override { |
509 | 15.1k | return function->evaluate_zonemap_filter(ctx, function_arguments); |
510 | 15.1k | } |
511 | | |
512 | 18.2k | bool can_evaluate_zonemap_filter(const VExprSPtrs& function_arguments) const override { |
513 | 18.2k | return function->can_evaluate_zonemap_filter(function_arguments); |
514 | 18.2k | } |
515 | | |
516 | | private: |
517 | | std::shared_ptr<IFunction> function; |
518 | | DataTypes arguments; |
519 | | DataTypePtr return_type; |
520 | | }; |
521 | | |
522 | | struct simple_function_creator_without_type0 { |
523 | | template <typename AggregateFunctionTemplate, typename... TArgs> |
524 | 171 | static std::shared_ptr<IFunction> create(const DataTypePtr& result_type, TArgs&&... args) { |
525 | 171 | std::unique_ptr<IFunction> result(std::make_unique<AggregateFunctionTemplate>( |
526 | 171 | result_type, std::forward<TArgs>(args)...)); |
527 | 171 | return std::shared_ptr<IFunction>(result.release()); |
528 | 171 | } _ZN5doris37simple_function_creator_without_type06createINS_25FunctionArrayAggDecimalV3INS_27ArrayAggregateImplDecimalV3ILNS_18AggregateOperationE2ELNS_13PrimitiveTypeE30EEENS_12NameArraySumEEEJEEESt10shared_ptrINS_9IFunctionEERKS9_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 524 | 12 | static std::shared_ptr<IFunction> create(const DataTypePtr& result_type, TArgs&&... args) { | 525 | 12 | std::unique_ptr<IFunction> result(std::make_unique<AggregateFunctionTemplate>( | 526 | 12 | result_type, std::forward<TArgs>(args)...)); | 527 | 12 | return std::shared_ptr<IFunction>(result.release()); | 528 | 12 | } |
_ZN5doris37simple_function_creator_without_type06createINS_25FunctionArrayAggDecimalV3INS_27ArrayAggregateImplDecimalV3ILNS_18AggregateOperationE2ELNS_13PrimitiveTypeE35EEENS_12NameArraySumEEEJEEESt10shared_ptrINS_9IFunctionEERKS9_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 524 | 29 | static std::shared_ptr<IFunction> create(const DataTypePtr& result_type, TArgs&&... args) { | 525 | 29 | std::unique_ptr<IFunction> result(std::make_unique<AggregateFunctionTemplate>( | 526 | 29 | result_type, std::forward<TArgs>(args)...)); | 527 | 29 | return std::shared_ptr<IFunction>(result.release()); | 528 | 29 | } |
_ZN5doris37simple_function_creator_without_type06createINS_25FunctionArrayAggDecimalV3INS_27ArrayAggregateImplDecimalV3ILNS_18AggregateOperationE3ELNS_13PrimitiveTypeE30EEENS_16NameArrayAverageEEEJEEESt10shared_ptrINS_9IFunctionEERKS9_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 524 | 11 | static std::shared_ptr<IFunction> create(const DataTypePtr& result_type, TArgs&&... args) { | 525 | 11 | std::unique_ptr<IFunction> result(std::make_unique<AggregateFunctionTemplate>( | 526 | 11 | result_type, std::forward<TArgs>(args)...)); | 527 | 11 | return std::shared_ptr<IFunction>(result.release()); | 528 | 11 | } |
_ZN5doris37simple_function_creator_without_type06createINS_25FunctionArrayAggDecimalV3INS_27ArrayAggregateImplDecimalV3ILNS_18AggregateOperationE3ELNS_13PrimitiveTypeE35EEENS_16NameArrayAverageEEEJEEESt10shared_ptrINS_9IFunctionEERKS9_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 524 | 31 | static std::shared_ptr<IFunction> create(const DataTypePtr& result_type, TArgs&&... args) { | 525 | 31 | std::unique_ptr<IFunction> result(std::make_unique<AggregateFunctionTemplate>( | 526 | 31 | result_type, std::forward<TArgs>(args)...)); | 527 | 31 | return std::shared_ptr<IFunction>(result.release()); | 528 | 31 | } |
_ZN5doris37simple_function_creator_without_type06createINS_25FunctionArrayAggDecimalV3INS_27ArrayAggregateImplDecimalV3ILNS_18AggregateOperationE4ELNS_13PrimitiveTypeE30EEENS_16NameArrayProductEEEJEEESt10shared_ptrINS_9IFunctionEERKS9_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 524 | 12 | static std::shared_ptr<IFunction> create(const DataTypePtr& result_type, TArgs&&... args) { | 525 | 12 | std::unique_ptr<IFunction> result(std::make_unique<AggregateFunctionTemplate>( | 526 | 12 | result_type, std::forward<TArgs>(args)...)); | 527 | 12 | return std::shared_ptr<IFunction>(result.release()); | 528 | 12 | } |
_ZN5doris37simple_function_creator_without_type06createINS_25FunctionArrayAggDecimalV3INS_27ArrayAggregateImplDecimalV3ILNS_18AggregateOperationE4ELNS_13PrimitiveTypeE35EEENS_16NameArrayProductEEEJEEESt10shared_ptrINS_9IFunctionEERKS9_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 524 | 31 | static std::shared_ptr<IFunction> create(const DataTypePtr& result_type, TArgs&&... args) { | 525 | 31 | std::unique_ptr<IFunction> result(std::make_unique<AggregateFunctionTemplate>( | 526 | 31 | result_type, std::forward<TArgs>(args)...)); | 527 | 31 | return std::shared_ptr<IFunction>(result.release()); | 528 | 31 | } |
_ZN5doris37simple_function_creator_without_type06createINS_19FunctionArrayCumSumILNS_13PrimitiveTypeE30EEEJEEESt10shared_ptrINS_9IFunctionEERKS5_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 524 | 14 | static std::shared_ptr<IFunction> create(const DataTypePtr& result_type, TArgs&&... args) { | 525 | 14 | std::unique_ptr<IFunction> result(std::make_unique<AggregateFunctionTemplate>( | 526 | 14 | result_type, std::forward<TArgs>(args)...)); | 527 | 14 | return std::shared_ptr<IFunction>(result.release()); | 528 | 14 | } |
_ZN5doris37simple_function_creator_without_type06createINS_19FunctionArrayCumSumILNS_13PrimitiveTypeE35EEEJEEESt10shared_ptrINS_9IFunctionEERKS5_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 524 | 31 | static std::shared_ptr<IFunction> create(const DataTypePtr& result_type, TArgs&&... args) { | 525 | 31 | std::unique_ptr<IFunction> result(std::make_unique<AggregateFunctionTemplate>( | 526 | 31 | result_type, std::forward<TArgs>(args)...)); | 527 | 31 | return std::shared_ptr<IFunction>(result.release()); | 528 | 31 | } |
|
529 | | }; |
530 | | template <template <PrimitiveType> class FunctionTemplate> |
531 | | struct SimpleFunctionCurryDirectWithResultType0 { |
532 | | template <PrimitiveType ResultType> |
533 | | using T = FunctionTemplate<ResultType>; |
534 | | }; |
535 | | template <PrimitiveType... AllowedTypes> |
536 | | struct simple_function_creator_with_result_type0 { |
537 | | template <typename Class, typename... TArgs> |
538 | | static std::shared_ptr<IFunction> create_base_with_result_type(const DataTypePtr& result_type, |
539 | 171 | TArgs&&... args) { |
540 | 171 | auto create = [&]<PrimitiveType ResultType>() { |
541 | 171 | return simple_function_creator_without_type0::create< |
542 | 171 | typename Class::template T<ResultType>>(result_type, |
543 | 171 | std::forward<TArgs>(args)...); |
544 | 171 | }; _ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_17ArraySumDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlTnS1_vE_clILS1_30EEEDav Line | Count | Source | 540 | 12 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 12 | return simple_function_creator_without_type0::create< | 542 | 12 | typename Class::template T<ResultType>>(result_type, | 543 | 12 | std::forward<TArgs>(args)...); | 544 | 12 | }; |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_17ArraySumDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlTnS1_vE_clILS1_35EEEDav Line | Count | Source | 540 | 29 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 29 | return simple_function_creator_without_type0::create< | 542 | 29 | typename Class::template T<ResultType>>(result_type, | 543 | 29 | std::forward<TArgs>(args)...); | 544 | 29 | }; |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_17ArrayAvgDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlTnS1_vE_clILS1_30EEEDav Line | Count | Source | 540 | 11 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 11 | return simple_function_creator_without_type0::create< | 542 | 11 | typename Class::template T<ResultType>>(result_type, | 543 | 11 | std::forward<TArgs>(args)...); | 544 | 11 | }; |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_17ArrayAvgDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlTnS1_vE_clILS1_35EEEDav Line | Count | Source | 540 | 31 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 31 | return simple_function_creator_without_type0::create< | 542 | 31 | typename Class::template T<ResultType>>(result_type, | 543 | 31 | std::forward<TArgs>(args)...); | 544 | 31 | }; |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_21ArrayProductDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlTnS1_vE_clILS1_30EEEDav Line | Count | Source | 540 | 12 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 12 | return simple_function_creator_without_type0::create< | 542 | 12 | typename Class::template T<ResultType>>(result_type, | 543 | 12 | std::forward<TArgs>(args)...); | 544 | 12 | }; |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_21ArrayProductDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlTnS1_vE_clILS1_35EEEDav Line | Count | Source | 540 | 31 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 31 | return simple_function_creator_without_type0::create< | 542 | 31 | typename Class::template T<ResultType>>(result_type, | 543 | 31 | std::forward<TArgs>(args)...); | 544 | 31 | }; |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_19FunctionArrayCumSumEEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlTnS1_vE_clILS1_30EEEDav Line | Count | Source | 540 | 14 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 14 | return simple_function_creator_without_type0::create< | 542 | 14 | typename Class::template T<ResultType>>(result_type, | 543 | 14 | std::forward<TArgs>(args)...); | 544 | 14 | }; |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_19FunctionArrayCumSumEEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlTnS1_vE_clILS1_35EEEDav Line | Count | Source | 540 | 31 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 31 | return simple_function_creator_without_type0::create< | 542 | 31 | typename Class::template T<ResultType>>(result_type, | 543 | 31 | std::forward<TArgs>(args)...); | 544 | 31 | }; |
|
545 | 171 | std::shared_ptr<IFunction> result = nullptr; |
546 | 171 | auto type = result_type->get_primitive_type(); |
547 | | |
548 | 171 | ( |
549 | 342 | [&] { |
550 | 342 | if (type == AllowedTypes) { |
551 | 171 | static_assert(AllowedTypes == TYPE_DECIMAL128I || |
552 | 171 | AllowedTypes == TYPE_DECIMAL256); |
553 | 171 | result = create.template operator()<AllowedTypes>(); |
554 | 171 | } |
555 | 342 | }(), _ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_17ArraySumDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlvE0_clEv Line | Count | Source | 549 | 41 | [&] { | 550 | 41 | if (type == AllowedTypes) { | 551 | 12 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 12 | AllowedTypes == TYPE_DECIMAL256); | 553 | 12 | result = create.template operator()<AllowedTypes>(); | 554 | 12 | } | 555 | 41 | }(), |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_17ArraySumDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlvE_clEv Line | Count | Source | 549 | 41 | [&] { | 550 | 41 | if (type == AllowedTypes) { | 551 | 29 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 29 | AllowedTypes == TYPE_DECIMAL256); | 553 | 29 | result = create.template operator()<AllowedTypes>(); | 554 | 29 | } | 555 | 41 | }(), |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_17ArrayAvgDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlvE0_clEv Line | Count | Source | 549 | 42 | [&] { | 550 | 42 | if (type == AllowedTypes) { | 551 | 11 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 11 | AllowedTypes == TYPE_DECIMAL256); | 553 | 11 | result = create.template operator()<AllowedTypes>(); | 554 | 11 | } | 555 | 42 | }(), |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_17ArrayAvgDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlvE_clEv Line | Count | Source | 549 | 42 | [&] { | 550 | 42 | if (type == AllowedTypes) { | 551 | 31 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 31 | AllowedTypes == TYPE_DECIMAL256); | 553 | 31 | result = create.template operator()<AllowedTypes>(); | 554 | 31 | } | 555 | 42 | }(), |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_21ArrayProductDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlvE0_clEv Line | Count | Source | 549 | 43 | [&] { | 550 | 43 | if (type == AllowedTypes) { | 551 | 12 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 12 | AllowedTypes == TYPE_DECIMAL256); | 553 | 12 | result = create.template operator()<AllowedTypes>(); | 554 | 12 | } | 555 | 43 | }(), |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_21ArrayProductDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlvE_clEv Line | Count | Source | 549 | 43 | [&] { | 550 | 43 | if (type == AllowedTypes) { | 551 | 31 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 31 | AllowedTypes == TYPE_DECIMAL256); | 553 | 31 | result = create.template operator()<AllowedTypes>(); | 554 | 31 | } | 555 | 43 | }(), |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_19FunctionArrayCumSumEEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlvE0_clEv Line | Count | Source | 549 | 45 | [&] { | 550 | 45 | if (type == AllowedTypes) { | 551 | 14 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 14 | AllowedTypes == TYPE_DECIMAL256); | 553 | 14 | result = create.template operator()<AllowedTypes>(); | 554 | 14 | } | 555 | 45 | }(), |
_ZZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_19FunctionArrayCumSumEEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ENKUlvE_clEv Line | Count | Source | 549 | 45 | [&] { | 550 | 45 | if (type == AllowedTypes) { | 551 | 31 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 31 | AllowedTypes == TYPE_DECIMAL256); | 553 | 31 | result = create.template operator()<AllowedTypes>(); | 554 | 31 | } | 555 | 45 | }(), |
|
556 | 171 | ...); |
557 | | |
558 | 171 | return result; |
559 | 171 | } _ZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_17ArraySumDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 539 | 41 | TArgs&&... args) { | 540 | 41 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 41 | return simple_function_creator_without_type0::create< | 542 | 41 | typename Class::template T<ResultType>>(result_type, | 543 | 41 | std::forward<TArgs>(args)...); | 544 | 41 | }; | 545 | 41 | std::shared_ptr<IFunction> result = nullptr; | 546 | 41 | auto type = result_type->get_primitive_type(); | 547 | | | 548 | 41 | ( | 549 | 41 | [&] { | 550 | 41 | if (type == AllowedTypes) { | 551 | 41 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 41 | AllowedTypes == TYPE_DECIMAL256); | 553 | 41 | result = create.template operator()<AllowedTypes>(); | 554 | 41 | } | 555 | 41 | }(), | 556 | 41 | ...); | 557 | | | 558 | 41 | return result; | 559 | 41 | } |
_ZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_17ArrayAvgDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 539 | 42 | TArgs&&... args) { | 540 | 42 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 42 | return simple_function_creator_without_type0::create< | 542 | 42 | typename Class::template T<ResultType>>(result_type, | 543 | 42 | std::forward<TArgs>(args)...); | 544 | 42 | }; | 545 | 42 | std::shared_ptr<IFunction> result = nullptr; | 546 | 42 | auto type = result_type->get_primitive_type(); | 547 | | | 548 | 42 | ( | 549 | 42 | [&] { | 550 | 42 | if (type == AllowedTypes) { | 551 | 42 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 42 | AllowedTypes == TYPE_DECIMAL256); | 553 | 42 | result = create.template operator()<AllowedTypes>(); | 554 | 42 | } | 555 | 42 | }(), | 556 | 42 | ...); | 557 | | | 558 | 42 | return result; | 559 | 42 | } |
_ZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_21ArrayProductDecimalV3EEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 539 | 43 | TArgs&&... args) { | 540 | 43 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 43 | return simple_function_creator_without_type0::create< | 542 | 43 | typename Class::template T<ResultType>>(result_type, | 543 | 43 | std::forward<TArgs>(args)...); | 544 | 43 | }; | 545 | 43 | std::shared_ptr<IFunction> result = nullptr; | 546 | 43 | auto type = result_type->get_primitive_type(); | 547 | | | 548 | 43 | ( | 549 | 43 | [&] { | 550 | 43 | if (type == AllowedTypes) { | 551 | 43 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 43 | AllowedTypes == TYPE_DECIMAL256); | 553 | 43 | result = create.template operator()<AllowedTypes>(); | 554 | 43 | } | 555 | 43 | }(), | 556 | 43 | ...); | 557 | | | 558 | 43 | return result; | 559 | 43 | } |
_ZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE28create_base_with_result_typeINS_40SimpleFunctionCurryDirectWithResultType0INS_19FunctionArrayCumSumEEEJEEESt10shared_ptrINS_9IFunctionEERKS7_IKNS_9IDataTypeEEDpOT0_ Line | Count | Source | 539 | 45 | TArgs&&... args) { | 540 | 45 | auto create = [&]<PrimitiveType ResultType>() { | 541 | 45 | return simple_function_creator_without_type0::create< | 542 | 45 | typename Class::template T<ResultType>>(result_type, | 543 | 45 | std::forward<TArgs>(args)...); | 544 | 45 | }; | 545 | 45 | std::shared_ptr<IFunction> result = nullptr; | 546 | 45 | auto type = result_type->get_primitive_type(); | 547 | | | 548 | 45 | ( | 549 | 45 | [&] { | 550 | 45 | if (type == AllowedTypes) { | 551 | 45 | static_assert(AllowedTypes == TYPE_DECIMAL128I || | 552 | 45 | AllowedTypes == TYPE_DECIMAL256); | 553 | 45 | result = create.template operator()<AllowedTypes>(); | 554 | 45 | } | 555 | 45 | }(), | 556 | 45 | ...); | 557 | | | 558 | 45 | return result; | 559 | 45 | } |
|
560 | | |
561 | | // Create agg function with result type from FE. |
562 | | // Currently only used for decimalv3 sum and avg. |
563 | | template <template <PrimitiveType> class FunctionTemplate> |
564 | 171 | static std::shared_ptr<IFunction> creator_with_result_type(const DataTypePtr& result_type) { |
565 | 171 | return create_base_with_result_type< |
566 | 171 | SimpleFunctionCurryDirectWithResultType0<FunctionTemplate>>(result_type); |
567 | 171 | } _ZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE24creator_with_result_typeINS_17ArraySumDecimalV3EEESt10shared_ptrINS_9IFunctionEERKS5_IKNS_9IDataTypeEE Line | Count | Source | 564 | 41 | static std::shared_ptr<IFunction> creator_with_result_type(const DataTypePtr& result_type) { | 565 | 41 | return create_base_with_result_type< | 566 | 41 | SimpleFunctionCurryDirectWithResultType0<FunctionTemplate>>(result_type); | 567 | 41 | } |
_ZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE24creator_with_result_typeINS_17ArrayAvgDecimalV3EEESt10shared_ptrINS_9IFunctionEERKS5_IKNS_9IDataTypeEE Line | Count | Source | 564 | 42 | static std::shared_ptr<IFunction> creator_with_result_type(const DataTypePtr& result_type) { | 565 | 42 | return create_base_with_result_type< | 566 | 42 | SimpleFunctionCurryDirectWithResultType0<FunctionTemplate>>(result_type); | 567 | 42 | } |
_ZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE24creator_with_result_typeINS_21ArrayProductDecimalV3EEESt10shared_ptrINS_9IFunctionEERKS5_IKNS_9IDataTypeEE Line | Count | Source | 564 | 43 | static std::shared_ptr<IFunction> creator_with_result_type(const DataTypePtr& result_type) { | 565 | 43 | return create_base_with_result_type< | 566 | 43 | SimpleFunctionCurryDirectWithResultType0<FunctionTemplate>>(result_type); | 567 | 43 | } |
_ZN5doris41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS1_35EEE24creator_with_result_typeINS_19FunctionArrayCumSumEEESt10shared_ptrINS_9IFunctionEERKS5_IKNS_9IDataTypeEE Line | Count | Source | 564 | 45 | static std::shared_ptr<IFunction> creator_with_result_type(const DataTypePtr& result_type) { | 565 | 45 | return create_base_with_result_type< | 566 | 45 | SimpleFunctionCurryDirectWithResultType0<FunctionTemplate>>(result_type); | 567 | 45 | } |
|
568 | | }; |
569 | | |
570 | | class DefaultFunctionBuilder : public FunctionBuilderImpl { |
571 | | public: |
572 | | explicit DefaultFunctionBuilder(std::shared_ptr<IFunction> function_) |
573 | 491k | : function(std::move(function_)) {} |
574 | | |
575 | | // template <template <PrimitiveType> class FunctionTemplate> |
576 | | explicit DefaultFunctionBuilder(DataTypePtr return_type) |
577 | 171 | : _return_type(std::move(return_type)) {} |
578 | | |
579 | | template <template <PrimitiveType> class FunctionTemplate> |
580 | 171 | static FunctionBuilderPtr create_array_agg_function_decimalv3(DataTypePtr return_type) { |
581 | 171 | auto builder = std::make_shared<DefaultFunctionBuilder>(return_type); |
582 | 171 | DataTypePtr real_return_type; |
583 | | // for array_cum_sum, the return type is array, |
584 | | // so here should check nested type |
585 | 171 | if (PrimitiveType::TYPE_ARRAY == return_type->get_primitive_type()) { |
586 | 45 | const DataTypeArray* data_type_array = |
587 | 45 | static_cast<const DataTypeArray*>(remove_nullable(return_type).get()); |
588 | 45 | real_return_type = data_type_array->get_nested_type(); |
589 | 126 | } else { |
590 | 126 | real_return_type = return_type; |
591 | 126 | } |
592 | 171 | builder->function = |
593 | 171 | simple_function_creator_with_result_type0<TYPE_DECIMAL128I, TYPE_DECIMAL256>:: |
594 | 171 | creator_with_result_type<FunctionTemplate>(real_return_type); |
595 | 171 | return builder; |
596 | 171 | } _ZN5doris22DefaultFunctionBuilder35create_array_agg_function_decimalv3INS_17ArraySumDecimalV3EEESt10shared_ptrINS_16IFunctionBuilderEES3_IKNS_9IDataTypeEE Line | Count | Source | 580 | 41 | static FunctionBuilderPtr create_array_agg_function_decimalv3(DataTypePtr return_type) { | 581 | 41 | auto builder = std::make_shared<DefaultFunctionBuilder>(return_type); | 582 | 41 | DataTypePtr real_return_type; | 583 | | // for array_cum_sum, the return type is array, | 584 | | // so here should check nested type | 585 | 41 | if (PrimitiveType::TYPE_ARRAY == return_type->get_primitive_type()) { | 586 | 0 | const DataTypeArray* data_type_array = | 587 | 0 | static_cast<const DataTypeArray*>(remove_nullable(return_type).get()); | 588 | 0 | real_return_type = data_type_array->get_nested_type(); | 589 | 41 | } else { | 590 | 41 | real_return_type = return_type; | 591 | 41 | } | 592 | 41 | builder->function = | 593 | 41 | simple_function_creator_with_result_type0<TYPE_DECIMAL128I, TYPE_DECIMAL256>:: | 594 | 41 | creator_with_result_type<FunctionTemplate>(real_return_type); | 595 | 41 | return builder; | 596 | 41 | } |
_ZN5doris22DefaultFunctionBuilder35create_array_agg_function_decimalv3INS_17ArrayAvgDecimalV3EEESt10shared_ptrINS_16IFunctionBuilderEES3_IKNS_9IDataTypeEE Line | Count | Source | 580 | 42 | static FunctionBuilderPtr create_array_agg_function_decimalv3(DataTypePtr return_type) { | 581 | 42 | auto builder = std::make_shared<DefaultFunctionBuilder>(return_type); | 582 | 42 | DataTypePtr real_return_type; | 583 | | // for array_cum_sum, the return type is array, | 584 | | // so here should check nested type | 585 | 42 | if (PrimitiveType::TYPE_ARRAY == return_type->get_primitive_type()) { | 586 | 0 | const DataTypeArray* data_type_array = | 587 | 0 | static_cast<const DataTypeArray*>(remove_nullable(return_type).get()); | 588 | 0 | real_return_type = data_type_array->get_nested_type(); | 589 | 42 | } else { | 590 | 42 | real_return_type = return_type; | 591 | 42 | } | 592 | 42 | builder->function = | 593 | 42 | simple_function_creator_with_result_type0<TYPE_DECIMAL128I, TYPE_DECIMAL256>:: | 594 | 42 | creator_with_result_type<FunctionTemplate>(real_return_type); | 595 | 42 | return builder; | 596 | 42 | } |
_ZN5doris22DefaultFunctionBuilder35create_array_agg_function_decimalv3INS_21ArrayProductDecimalV3EEESt10shared_ptrINS_16IFunctionBuilderEES3_IKNS_9IDataTypeEE Line | Count | Source | 580 | 43 | static FunctionBuilderPtr create_array_agg_function_decimalv3(DataTypePtr return_type) { | 581 | 43 | auto builder = std::make_shared<DefaultFunctionBuilder>(return_type); | 582 | 43 | DataTypePtr real_return_type; | 583 | | // for array_cum_sum, the return type is array, | 584 | | // so here should check nested type | 585 | 43 | if (PrimitiveType::TYPE_ARRAY == return_type->get_primitive_type()) { | 586 | 0 | const DataTypeArray* data_type_array = | 587 | 0 | static_cast<const DataTypeArray*>(remove_nullable(return_type).get()); | 588 | 0 | real_return_type = data_type_array->get_nested_type(); | 589 | 43 | } else { | 590 | 43 | real_return_type = return_type; | 591 | 43 | } | 592 | 43 | builder->function = | 593 | 43 | simple_function_creator_with_result_type0<TYPE_DECIMAL128I, TYPE_DECIMAL256>:: | 594 | 43 | creator_with_result_type<FunctionTemplate>(real_return_type); | 595 | 43 | return builder; | 596 | 43 | } |
_ZN5doris22DefaultFunctionBuilder35create_array_agg_function_decimalv3INS_19FunctionArrayCumSumEEESt10shared_ptrINS_16IFunctionBuilderEES3_IKNS_9IDataTypeEE Line | Count | Source | 580 | 45 | static FunctionBuilderPtr create_array_agg_function_decimalv3(DataTypePtr return_type) { | 581 | 45 | auto builder = std::make_shared<DefaultFunctionBuilder>(return_type); | 582 | 45 | DataTypePtr real_return_type; | 583 | | // for array_cum_sum, the return type is array, | 584 | | // so here should check nested type | 585 | 45 | if (PrimitiveType::TYPE_ARRAY == return_type->get_primitive_type()) { | 586 | 45 | const DataTypeArray* data_type_array = | 587 | 45 | static_cast<const DataTypeArray*>(remove_nullable(return_type).get()); | 588 | 45 | real_return_type = data_type_array->get_nested_type(); | 589 | 45 | } else { | 590 | 0 | real_return_type = return_type; | 591 | 0 | } | 592 | 45 | builder->function = | 593 | 45 | simple_function_creator_with_result_type0<TYPE_DECIMAL128I, TYPE_DECIMAL256>:: | 594 | 45 | creator_with_result_type<FunctionTemplate>(real_return_type); | 595 | 45 | return builder; | 596 | 45 | } |
|
597 | | |
598 | 479k | void check_number_of_arguments(size_t number_of_arguments) const override { |
599 | 479k | function->check_number_of_arguments(number_of_arguments); |
600 | 479k | } |
601 | | |
602 | 509 | String get_name() const override { return function->get_name(); } |
603 | 1.16k | bool is_variadic() const override { return function->is_variadic(); } |
604 | 0 | size_t get_number_of_arguments() const override { return function->get_number_of_arguments(); } |
605 | | |
606 | 0 | ColumnNumbers get_arguments_that_are_always_constant() const override { |
607 | 0 | return function->get_arguments_that_are_always_constant(); |
608 | 0 | } |
609 | | |
610 | | protected: |
611 | 0 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
612 | 0 | return function->get_return_type_impl(arguments); |
613 | 0 | } |
614 | 480k | DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { |
615 | 480k | return function->get_return_type_impl(arguments); |
616 | 480k | } |
617 | | |
618 | 479k | bool use_default_implementation_for_nulls() const override { |
619 | 479k | return function->use_default_implementation_for_nulls(); |
620 | 479k | } |
621 | | |
622 | 480k | bool skip_return_type_check() const override { return function->skip_return_type_check(); } |
623 | | |
624 | 0 | bool need_replace_null_data_to_default() const override { |
625 | 0 | return function->need_replace_null_data_to_default(); |
626 | 0 | } |
627 | | |
628 | | FunctionBasePtr build_impl(const ColumnsWithTypeAndName& arguments, |
629 | 479k | const DataTypePtr& return_type) const override { |
630 | 479k | DataTypes data_types(arguments.size()); |
631 | 1.41M | for (size_t i = 0; i < arguments.size(); ++i) { |
632 | 933k | data_types[i] = arguments[i].type; |
633 | 933k | } |
634 | 479k | return std::make_shared<DefaultFunction>(function, data_types, return_type); |
635 | 479k | } |
636 | | |
637 | 9.52k | DataTypes get_variadic_argument_types_impl() const override { |
638 | 9.52k | return function->get_variadic_argument_types_impl(); |
639 | 9.52k | } |
640 | | |
641 | | private: |
642 | | std::shared_ptr<IFunction> function; |
643 | | DataTypePtr _return_type; |
644 | | }; |
645 | | |
646 | | using FunctionPtr = std::shared_ptr<IFunction>; |
647 | | /** Return ColumnNullable of src, with null map as OR-ed null maps of args columns in blocks. |
648 | | * Or ColumnConst(ColumnNullable) if the result is always NULL or if the result is constant and always not NULL. |
649 | | */ |
650 | | ColumnPtr wrap_in_nullable(const ColumnPtr& src, const Block& block, const ColumnNumbers& args, |
651 | | size_t input_rows_count); |
652 | | |
653 | | } // namespace doris |