/root/doris/be/src/vec/functions/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 "olap/rowset/segment_v2/inverted_index_iterator.h" // IWYU pragma: keep |
35 | | #include "runtime/define_primitive_type.h" |
36 | | #include "udf/udf.h" |
37 | | #include "vec/core/block.h" |
38 | | #include "vec/core/column_numbers.h" |
39 | | #include "vec/core/column_with_type_and_name.h" |
40 | | #include "vec/core/columns_with_type_and_name.h" |
41 | | #include "vec/core/types.h" |
42 | | #include "vec/data_types/data_type.h" |
43 | | #include "vec/data_types/data_type_array.h" |
44 | | #include "vec/data_types/data_type_map.h" |
45 | | #include "vec/data_types/data_type_nullable.h" |
46 | | #include "vec/data_types/data_type_struct.h" |
47 | | |
48 | | namespace doris::vectorized { |
49 | | |
50 | | struct FunctionAttr { |
51 | | bool enable_decimal256 {false}; |
52 | | bool new_version_unix_timestamp {false}; |
53 | | }; |
54 | | |
55 | | #define RETURN_REAL_TYPE_FOR_DATEV2_FUNCTION(TYPE) \ |
56 | 37 | bool is_nullable = false; \ |
57 | 37 | bool is_datev2 = false; \ |
58 | 65 | for (auto it : arguments) { \ |
59 | 65 | is_nullable = is_nullable || it.type->is_nullable(); \ |
60 | 65 | is_datev2 = is_datev2 || it.type->get_primitive_type() == TYPE_DATEV2 || \ |
61 | 65 | it.type->get_primitive_type() == TYPE_DATETIMEV2; \ |
62 | 65 | } \ |
63 | 37 | return is_nullable || !is_datev2 \ |
64 | 37 | ? make_nullable( \ |
65 | 31 | std::make_shared<typename PrimitiveTypeTraits<TYPE>::DataType>()) \ |
66 | 37 | : std::make_shared<typename PrimitiveTypeTraits<TYPE>::DataType>(); |
67 | | |
68 | | #define SET_NULLMAP_IF_FALSE(EXPR) \ |
69 | | if (!EXPR) [[unlikely]] { \ |
70 | | null_map[i] = true; \ |
71 | | } |
72 | | |
73 | | class Field; |
74 | | class VExpr; |
75 | | |
76 | | // Only use dispose the variadic argument |
77 | | template <typename T> |
78 | | auto has_variadic_argument_types(T&& arg) -> decltype(T::get_variadic_argument_types()) {}; |
79 | | void has_variadic_argument_types(...); |
80 | | |
81 | | template <typename T> |
82 | | concept HasGetVariadicArgumentTypesImpl = requires(T t) { |
83 | | { t.get_variadic_argument_types_impl() } -> std::same_as<DataTypes>; |
84 | | }; |
85 | | |
86 | | bool have_null_column(const Block& block, const ColumnNumbers& args); |
87 | | bool have_null_column(const ColumnsWithTypeAndName& args); |
88 | | |
89 | | /// The simplest executable object. |
90 | | /// Motivation: |
91 | | /// * Prepare something heavy once before main execution loop instead of doing it for each block. |
92 | | /// * Provide const interface for IFunctionBase (later). |
93 | | class IPreparedFunction { |
94 | | public: |
95 | 101k | virtual ~IPreparedFunction() = default; |
96 | | |
97 | | /// Get the main function name. |
98 | | virtual String get_name() const = 0; |
99 | | |
100 | | virtual Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
101 | | uint32_t result, size_t input_rows_count) const = 0; |
102 | | }; |
103 | | |
104 | | using PreparedFunctionPtr = std::shared_ptr<IPreparedFunction>; |
105 | | |
106 | | class PreparedFunctionImpl : public IPreparedFunction { |
107 | | public: |
108 | | Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
109 | | uint32_t result, size_t input_rows_count) const final; |
110 | | |
111 | | /** If the function have non-zero number of arguments, |
112 | | * and if all arguments are constant, that we could automatically provide default implementation: |
113 | | * arguments are converted to ordinary columns with single value which is not const, then function is executed as usual, |
114 | | * and then the result is converted to constant column. |
115 | | */ |
116 | 108k | virtual bool use_default_implementation_for_constants() const { return true; } |
117 | | |
118 | | /** If use_default_implementation_for_nulls() is true, after execute the function, |
119 | | * whether need to replace the nested data of null data to the default value. |
120 | | * E.g. for binary arithmetic exprs, need return true to avoid false overflow. |
121 | | */ |
122 | 0 | virtual bool need_replace_null_data_to_default() const { return false; } |
123 | | |
124 | | protected: |
125 | | virtual Status execute_impl(FunctionContext* context, Block& block, |
126 | | const ColumnNumbers& arguments, uint32_t result, |
127 | | size_t input_rows_count) const = 0; |
128 | | |
129 | | /** Default implementation in presence of Nullable arguments or NULL constants as arguments is the following: |
130 | | * if some of arguments are NULL constants then return NULL constant, |
131 | | * if some of arguments are Nullable, then execute function as usual for block, |
132 | | * where Nullable columns are substituted with nested columns (they have arbitrary values in rows corresponding to NULL value) |
133 | | * and wrap result in Nullable column where NULLs are in all rows where any of arguments are NULL. |
134 | | */ |
135 | 0 | virtual bool use_default_implementation_for_nulls() const { return true; } |
136 | | |
137 | 0 | virtual bool skip_return_type_check() const { return false; } |
138 | | |
139 | | /** Some arguments could remain constant during this implementation. |
140 | | * Every argument required const must write here and no checks elsewhere. |
141 | | */ |
142 | 0 | virtual ColumnNumbers get_arguments_that_are_always_constant() const { return {}; } |
143 | | |
144 | | private: |
145 | | Status default_implementation_for_nulls(FunctionContext* context, Block& block, |
146 | | const ColumnNumbers& args, uint32_t result, |
147 | | size_t input_rows_count, bool* executed) const; |
148 | | Status default_implementation_for_constant_arguments(FunctionContext* context, Block& block, |
149 | | const ColumnNumbers& args, uint32_t result, |
150 | | size_t input_rows_count, |
151 | | bool* executed) const; |
152 | | Status default_execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
153 | | uint32_t result, size_t input_rows_count) const; |
154 | | Status _execute_skipped_constant_deal(FunctionContext* context, Block& block, |
155 | | const ColumnNumbers& args, uint32_t result, |
156 | | size_t input_rows_count) const; |
157 | | }; |
158 | | |
159 | | /// Function with known arguments and return type. |
160 | | class IFunctionBase { |
161 | | public: |
162 | 116k | virtual ~IFunctionBase() = default; |
163 | | |
164 | | /// Get the main function name. |
165 | | virtual String get_name() const = 0; |
166 | | |
167 | | virtual const DataTypes& get_argument_types() const = 0; |
168 | | virtual const DataTypePtr& get_return_type() const = 0; |
169 | | |
170 | | /// Do preparations and return executable. |
171 | | /// sample_block should contain data types of arguments and values of constants, if relevant. |
172 | | virtual PreparedFunctionPtr prepare(FunctionContext* context, const Block& sample_block, |
173 | | const ColumnNumbers& arguments, uint32_t result) const = 0; |
174 | | |
175 | | /// Override this when function need to store state in the `FunctionContext`, or do some |
176 | | /// preparation work according to information from `FunctionContext`. |
177 | 74.4k | virtual Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) { |
178 | 74.4k | return Status::OK(); |
179 | 74.4k | } |
180 | | |
181 | | Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
182 | 99.6k | uint32_t result, size_t input_rows_count) const { |
183 | 99.6k | try { |
184 | 99.6k | return prepare(context, block, arguments, result) |
185 | 99.6k | ->execute(context, block, arguments, result, input_rows_count); |
186 | 99.6k | } catch (const Exception& e) { |
187 | 1 | return e.to_status(); |
188 | 1 | } |
189 | 99.6k | } |
190 | | |
191 | | virtual Status evaluate_inverted_index( |
192 | | const ColumnsWithTypeAndName& arguments, |
193 | | const std::vector<vectorized::IndexFieldNameAndTypePair>& data_type_with_names, |
194 | | std::vector<segment_v2::IndexIterator*> iterators, uint32_t num_rows, |
195 | 0 | segment_v2::InvertedIndexResultBitmap& bitmap_result) const { |
196 | 0 | return Status::OK(); |
197 | 0 | } |
198 | | |
199 | | /// Do cleaning work when function is finished, i.e., release state variables in the |
200 | | /// `FunctionContext` which are registered in `prepare` phase. |
201 | 51.0k | virtual Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) { |
202 | 51.0k | return Status::OK(); |
203 | 51.0k | } |
204 | | |
205 | | virtual bool is_use_default_implementation_for_constants() const = 0; |
206 | | |
207 | 0 | virtual bool is_udf_function() const { return false; } |
208 | | |
209 | 0 | virtual bool can_push_down_to_index() const { return false; } |
210 | | |
211 | 0 | virtual bool is_blockable() const { return false; } |
212 | | }; |
213 | | |
214 | | using FunctionBasePtr = std::shared_ptr<IFunctionBase>; |
215 | | |
216 | | /// Creates IFunctionBase from argument types list. |
217 | | class IFunctionBuilder { |
218 | | public: |
219 | 118k | virtual ~IFunctionBuilder() = default; |
220 | | |
221 | | /// Get the main function name. |
222 | | virtual String get_name() const = 0; |
223 | | |
224 | | /// Override and return true if function could take different number of arguments. |
225 | | ///TODO: this function is not actually used now. but in check_number_of_arguments we still need it because for many |
226 | | /// functions we didn't set the correct number of arguments. |
227 | | virtual bool is_variadic() const = 0; |
228 | | |
229 | | /// For non-variadic functions, return number of arguments; otherwise return zero (that should be ignored). |
230 | | virtual size_t get_number_of_arguments() const = 0; |
231 | | |
232 | | /// Throw if number of arguments is incorrect. Default implementation will check only in non-variadic case. |
233 | | virtual void check_number_of_arguments(size_t number_of_arguments) const = 0; |
234 | | |
235 | | /// Check arguments and return IFunctionBase. |
236 | | virtual FunctionBasePtr build(const ColumnsWithTypeAndName& arguments, |
237 | | const DataTypePtr& return_type) const = 0; |
238 | | |
239 | | /// For higher-order functions (functions, that have lambda expression as at least one argument). |
240 | | /// You pass data types with empty DataTypeFunction for lambda arguments. |
241 | | /// This function will replace it with DataTypeFunction containing actual types. |
242 | | virtual DataTypes get_variadic_argument_types() const = 0; |
243 | | |
244 | | /// Returns indexes of arguments, that must be ColumnConst |
245 | | virtual ColumnNumbers get_arguments_that_are_always_constant() const = 0; |
246 | | }; |
247 | | |
248 | | using FunctionBuilderPtr = std::shared_ptr<IFunctionBuilder>; |
249 | | |
250 | 3 | inline std::string get_types_string(const ColumnsWithTypeAndName& arguments) { |
251 | 3 | std::string types; |
252 | 3 | for (const auto& argument : arguments) { |
253 | 2 | if (!types.empty()) { |
254 | 1 | types += ", "; |
255 | 1 | } |
256 | 2 | types += argument.type->get_name(); |
257 | 2 | } |
258 | 3 | return types; |
259 | 3 | } |
260 | | |
261 | | /// used in function_factory. when we register a function, save a builder. to get a function, to get a builder. |
262 | | /// will use DefaultFunctionBuilder as the default builder in function's registration if we didn't explicitly specify. |
263 | | class FunctionBuilderImpl : public IFunctionBuilder { |
264 | | public: |
265 | | FunctionBasePtr build(const ColumnsWithTypeAndName& arguments, |
266 | 100k | const DataTypePtr& return_type) const final { |
267 | 100k | if (skip_return_type_check()) { |
268 | 85.9k | return build_impl(arguments, return_type); |
269 | 85.9k | } |
270 | 14.3k | const DataTypePtr& func_return_type = get_return_type(arguments); |
271 | 14.3k | if (func_return_type == nullptr) { |
272 | 1 | throw doris::Exception( |
273 | 1 | ErrorCode::INTERNAL_ERROR, |
274 | 1 | "function return type check failed, function_name={}, " |
275 | 1 | "expect_return_type={}, real_return_type is nullptr, input_arguments={}", |
276 | 1 | get_name(), return_type->get_name(), get_types_string(arguments)); |
277 | 1 | } |
278 | | |
279 | | // check return types equal. |
280 | 14.3k | if (!(return_type->equals(*func_return_type) || |
281 | | // For null constant argument, `get_return_type` would return |
282 | | // Nullable<DataTypeNothing> when `use_default_implementation_for_nulls` is true. |
283 | 14.3k | (return_type->is_nullable() && func_return_type->is_nullable() && |
284 | 11 | ((DataTypeNullable*)func_return_type.get()) |
285 | 6 | ->get_nested_type() |
286 | 6 | ->get_primitive_type() == INVALID_TYPE) || |
287 | 14.3k | is_date_or_datetime_or_decimal(return_type, func_return_type) || |
288 | 14.3k | is_nested_type_date_or_datetime_or_decimal(return_type, func_return_type))) { |
289 | 2 | throw doris::Exception( |
290 | 2 | ErrorCode::INTERNAL_ERROR, |
291 | 2 | "function return type check failed, function_name={}, " |
292 | 2 | "fe plan return type={}, be real return type={}, input_arguments={}", |
293 | 2 | get_name(), return_type->get_name(), func_return_type->get_name(), |
294 | 2 | get_types_string(arguments)); |
295 | 2 | } |
296 | 14.3k | return build_impl(arguments, return_type); |
297 | 14.3k | } |
298 | | |
299 | 10.6k | bool is_variadic() const override { return false; } |
300 | | |
301 | | // Default implementation. Will check only in non-variadic case. |
302 | | void check_number_of_arguments(size_t number_of_arguments) const override; |
303 | | // the return type should be same with what FE plans. |
304 | | // it returns: `get_return_type_impl` if `use_default_implementation_for_nulls` = false |
305 | | // `get_return_type_impl` warpped in NULL if `use_default_implementation_for_nulls` = true and input has NULL |
306 | | DataTypePtr get_return_type(const ColumnsWithTypeAndName& arguments) const; |
307 | | |
308 | 1.01k | DataTypes get_variadic_argument_types() const override { |
309 | 1.01k | return get_variadic_argument_types_impl(); |
310 | 1.01k | } |
311 | | |
312 | 0 | ColumnNumbers get_arguments_that_are_always_constant() const override { return {}; } |
313 | | |
314 | | protected: |
315 | | // Get the result type by argument type. If the function does not apply to these arguments, throw an exception. |
316 | | // the get_return_type_impl and its overrides should only return the nested type if `use_default_implementation_for_nulls` is true. |
317 | | // whether to wrap in nullable type will be automatically decided. |
318 | 14.0k | virtual DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const { |
319 | 14.0k | DataTypes data_types(arguments.size()); |
320 | 52.4k | for (size_t i = 0; i < arguments.size(); ++i) { |
321 | 38.4k | data_types[i] = arguments[i].type; |
322 | 38.4k | } |
323 | 14.0k | return get_return_type_impl(data_types); |
324 | 14.0k | } |
325 | | |
326 | 0 | virtual DataTypePtr get_return_type_impl(const DataTypes& /*arguments*/) const { |
327 | 0 | throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, |
328 | 0 | "get_return_type is not implemented for {}", get_name()); |
329 | 0 | return nullptr; |
330 | 0 | } |
331 | | |
332 | | /** If use_default_implementation_for_nulls() is true, than change arguments for get_return_type() and build_impl(): |
333 | | * if some of arguments are Nullable(Nothing) then don't call get_return_type(), call build_impl() with return_type = Nullable(Nothing), |
334 | | * if some of arguments are Nullable, then: |
335 | | * - Nullable types are substituted with nested types for get_return_type() function |
336 | | * - WRAP get_return_type() RESULT IN NULLABLE type and pass to build_impl |
337 | | * |
338 | | * Otherwise build returns build_impl(arguments, get_return_type(arguments)); |
339 | | */ |
340 | 0 | virtual bool use_default_implementation_for_nulls() const { return true; } |
341 | | |
342 | 0 | virtual bool skip_return_type_check() const { return false; } |
343 | | |
344 | 0 | virtual bool need_replace_null_data_to_default() const { return false; } |
345 | | |
346 | | /// return a real function object to execute. called in build(...). |
347 | | virtual FunctionBasePtr build_impl(const ColumnsWithTypeAndName& arguments, |
348 | | const DataTypePtr& return_type) const = 0; |
349 | | |
350 | 354 | virtual DataTypes get_variadic_argument_types_impl() const { return {}; } |
351 | | |
352 | | private: |
353 | | bool is_date_or_datetime_or_decimal(const DataTypePtr& return_type, |
354 | | const DataTypePtr& func_return_type) const; |
355 | | bool is_nested_type_date_or_datetime_or_decimal(const DataTypePtr& return_type, |
356 | | const DataTypePtr& func_return_type) const; |
357 | | }; |
358 | | |
359 | | /// Previous function interface. |
360 | | class IFunction : public std::enable_shared_from_this<IFunction>, |
361 | | public FunctionBuilderImpl, |
362 | | public IFunctionBase, |
363 | | public PreparedFunctionImpl { |
364 | | public: |
365 | | String get_name() const override = 0; |
366 | | |
367 | | /// Notice: We should not change the column in the block, because the column may be shared by multiple expressions or exec nodes. |
368 | | Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments, |
369 | | uint32_t result, size_t input_rows_count) const override = 0; |
370 | | |
371 | | /// Override this functions to change default implementation behavior. See details in IMyFunction. |
372 | 35.7k | bool use_default_implementation_for_nulls() const override { return true; } |
373 | | |
374 | 14.3k | bool skip_return_type_check() const override { return false; } |
375 | | |
376 | 8.77k | bool need_replace_null_data_to_default() const override { return false; } |
377 | | |
378 | | /// all constancy check should use this function to do automatically |
379 | 23.1k | ColumnNumbers get_arguments_that_are_always_constant() const override { return {}; } |
380 | | |
381 | 35 | bool is_use_default_implementation_for_constants() const override { |
382 | 35 | return use_default_implementation_for_constants(); |
383 | 35 | } |
384 | | |
385 | | using PreparedFunctionImpl::execute; |
386 | | using FunctionBuilderImpl::get_return_type_impl; |
387 | | using FunctionBuilderImpl::get_variadic_argument_types_impl; |
388 | | using FunctionBuilderImpl::get_return_type; |
389 | | |
390 | | [[noreturn]] PreparedFunctionPtr prepare(FunctionContext* context, |
391 | | const Block& /*sample_block*/, |
392 | | const ColumnNumbers& /*arguments*/, |
393 | 0 | uint32_t /*result*/) const final { |
394 | 0 | throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, |
395 | 0 | "prepare is not implemented for IFunction {}", get_name()); |
396 | 0 | __builtin_unreachable(); |
397 | 0 | } |
398 | | |
399 | 26.5k | Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { |
400 | 26.5k | return Status::OK(); |
401 | 26.5k | } |
402 | | |
403 | 0 | [[noreturn]] const DataTypes& get_argument_types() const final { |
404 | 0 | throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, |
405 | 0 | "get_argument_types is not implemented for IFunction {}", |
406 | 0 | get_name()); |
407 | 0 | __builtin_unreachable(); |
408 | 0 | } |
409 | | |
410 | 0 | [[noreturn]] const DataTypePtr& get_return_type() const final { |
411 | 0 | throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, |
412 | 0 | "get_return_type is not implemented for IFunction {}", get_name()); |
413 | 0 | __builtin_unreachable(); |
414 | 0 | } |
415 | | |
416 | | protected: |
417 | | FunctionBasePtr build_impl(const ColumnsWithTypeAndName& /*arguments*/, |
418 | 0 | const DataTypePtr& /*return_type*/) const final { |
419 | 0 | throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR, |
420 | 0 | "build_impl is not implemented for IFunction {}", get_name()); |
421 | 0 | __builtin_unreachable(); |
422 | 0 | return {}; |
423 | 0 | } |
424 | | }; |
425 | | |
426 | | /* |
427 | | * when we register a function which didn't specify its base(i.e. inherited from IFunction), actually we use this as a wrapper. |
428 | | * it saves real implementation as `function`. |
429 | | */ |
430 | | class DefaultFunction final : public IFunctionBase { |
431 | | public: |
432 | | DefaultFunction(std::shared_ptr<IFunction> function_, DataTypes arguments_, |
433 | | DataTypePtr return_type_) |
434 | 14.3k | : function(std::move(function_)), |
435 | 14.3k | arguments(std::move(arguments_)), |
436 | 14.3k | return_type(std::move(return_type_)) {} |
437 | | |
438 | 0 | String get_name() const override { return function->get_name(); } |
439 | | |
440 | 0 | const DataTypes& get_argument_types() const override { return arguments; } |
441 | 1 | const DataTypePtr& get_return_type() const override { return return_type; } |
442 | | |
443 | | // return a default wrapper for IFunction. |
444 | | PreparedFunctionPtr prepare(FunctionContext* context, const Block& /*sample_block*/, |
445 | | const ColumnNumbers& /*arguments*/, |
446 | 14.2k | uint32_t /*result*/) const override { |
447 | 14.2k | return function; |
448 | 14.2k | } |
449 | | |
450 | 28.2k | Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { |
451 | 28.2k | return function->open(context, scope); |
452 | 28.2k | } |
453 | | |
454 | 28.2k | Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override { |
455 | 28.2k | return function->close(context, scope); |
456 | 28.2k | } |
457 | | |
458 | | Status evaluate_inverted_index( |
459 | | const ColumnsWithTypeAndName& args, |
460 | | const std::vector<vectorized::IndexFieldNameAndTypePair>& data_type_with_names, |
461 | | std::vector<segment_v2::IndexIterator*> iterators, uint32_t num_rows, |
462 | 0 | segment_v2::InvertedIndexResultBitmap& bitmap_result) const override { |
463 | 0 | return function->evaluate_inverted_index(args, data_type_with_names, iterators, num_rows, |
464 | 0 | bitmap_result); |
465 | 0 | } |
466 | | |
467 | 35 | bool is_use_default_implementation_for_constants() const override { |
468 | 35 | return function->is_use_default_implementation_for_constants(); |
469 | 35 | } |
470 | | |
471 | 0 | bool can_push_down_to_index() const override { return function->can_push_down_to_index(); } |
472 | | |
473 | 0 | bool is_blockable() const override { return function->is_blockable(); } |
474 | | |
475 | | private: |
476 | | std::shared_ptr<IFunction> function; |
477 | | DataTypes arguments; |
478 | | DataTypePtr return_type; |
479 | | }; |
480 | | |
481 | | class DefaultFunctionBuilder : public FunctionBuilderImpl { |
482 | | public: |
483 | | explicit DefaultFunctionBuilder(std::shared_ptr<IFunction> function_) |
484 | 16.3k | : function(std::move(function_)) {} |
485 | | |
486 | 14.3k | void check_number_of_arguments(size_t number_of_arguments) const override { |
487 | 14.3k | function->check_number_of_arguments(number_of_arguments); |
488 | 14.3k | } |
489 | | |
490 | 494 | String get_name() const override { return function->get_name(); } |
491 | 981 | bool is_variadic() const override { return function->is_variadic(); } |
492 | 0 | size_t get_number_of_arguments() const override { return function->get_number_of_arguments(); } |
493 | | |
494 | 0 | ColumnNumbers get_arguments_that_are_always_constant() const override { |
495 | 0 | return function->get_arguments_that_are_always_constant(); |
496 | 0 | } |
497 | | |
498 | | protected: |
499 | 0 | DataTypePtr get_return_type_impl(const DataTypes& arguments) const override { |
500 | 0 | return function->get_return_type_impl(arguments); |
501 | 0 | } |
502 | 14.3k | DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override { |
503 | 14.3k | return function->get_return_type_impl(arguments); |
504 | 14.3k | } |
505 | | |
506 | 14.3k | bool use_default_implementation_for_nulls() const override { |
507 | 14.3k | return function->use_default_implementation_for_nulls(); |
508 | 14.3k | } |
509 | | |
510 | 14.3k | bool skip_return_type_check() const override { return function->skip_return_type_check(); } |
511 | | |
512 | 0 | bool need_replace_null_data_to_default() const override { |
513 | 0 | return function->need_replace_null_data_to_default(); |
514 | 0 | } |
515 | | |
516 | | FunctionBasePtr build_impl(const ColumnsWithTypeAndName& arguments, |
517 | 14.3k | const DataTypePtr& return_type) const override { |
518 | 14.3k | DataTypes data_types(arguments.size()); |
519 | 53.1k | for (size_t i = 0; i < arguments.size(); ++i) { |
520 | 38.8k | data_types[i] = arguments[i].type; |
521 | 38.8k | } |
522 | 14.3k | return std::make_shared<DefaultFunction>(function, data_types, return_type); |
523 | 14.3k | } |
524 | | |
525 | 1.01k | DataTypes get_variadic_argument_types_impl() const override { |
526 | 1.01k | return function->get_variadic_argument_types_impl(); |
527 | 1.01k | } |
528 | | |
529 | | private: |
530 | | std::shared_ptr<IFunction> function; |
531 | | }; |
532 | | |
533 | | using FunctionPtr = std::shared_ptr<IFunction>; |
534 | | /** Return ColumnNullable of src, with null map as OR-ed null maps of args columns in blocks. |
535 | | * Or ColumnConst(ColumnNullable) if the result is always NULL or if the result is constant and always not NULL. |
536 | | */ |
537 | | ColumnPtr wrap_in_nullable(const ColumnPtr& src, const Block& block, const ColumnNumbers& args, |
538 | | size_t input_rows_count); |
539 | | |
540 | | } // namespace doris::vectorized |