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