Coverage Report

Created: 2026-07-12 00:10

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