Coverage Report

Created: 2025-05-09 19:27

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