Coverage Report

Created: 2025-12-30 18:18

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/vec/functions/function.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
// This file is copied from
18
// https://github.com/ClickHouse/ClickHouse/blob/master/src/Functions/IFunction.h
19
// and modified by Doris
20
21
#pragma once
22
23
#include <fmt/format.h>
24
#include <glog/logging.h>
25
26
#include <cstddef>
27
#include <memory>
28
#include <string>
29
#include <utility>
30
31
#include "common/exception.h"
32
#include "common/logging.h"
33
#include "common/status.h"
34
#include "olap/rowset/segment_v2/inverted_index_iterator.h" // IWYU pragma: keep
35
#include "runtime/define_primitive_type.h"
36
#include "udf/udf.h"
37
#include "vec/core/block.h"
38
#include "vec/core/column_numbers.h"
39
#include "vec/core/column_with_type_and_name.h"
40
#include "vec/core/columns_with_type_and_name.h"
41
#include "vec/core/types.h"
42
#include "vec/data_types/data_type.h"
43
#include "vec/data_types/data_type_array.h"
44
#include "vec/data_types/data_type_map.h"
45
#include "vec/data_types/data_type_nullable.h"
46
#include "vec/data_types/data_type_struct.h"
47
48
namespace doris {
49
struct InvertedIndexAnalyzerCtx;
50
} // namespace doris
51
52
namespace doris::vectorized {
53
54
struct FunctionAttr {
55
    bool new_version_unix_timestamp {false};
56
};
57
58
#define RETURN_REAL_TYPE_FOR_DATEV2_FUNCTION(TYPE)                                             \
59
43
    bool is_nullable = false;                                                                  \
60
43
    bool is_datev2 = false;                                                                    \
61
77
    for (auto it : arguments) {                                                                \
62
77
        is_nullable = is_nullable || it.type->is_nullable();                                   \
63
77
        is_datev2 = is_datev2 || it.type->get_primitive_type() == TYPE_DATEV2 ||               \
64
77
                    it.type->get_primitive_type() == TYPE_DATETIMEV2;                          \
65
77
    }                                                                                          \
66
43
    return is_nullable || !is_datev2                                                           \
67
43
                   ? make_nullable(                                                            \
68
37
                             std::make_shared<typename PrimitiveTypeTraits<TYPE>::DataType>()) \
69
43
                   : std::make_shared<typename PrimitiveTypeTraits<TYPE>::DataType>();
70
71
#define SET_NULLMAP_IF_FALSE(EXPR) \
72
    if (!EXPR) [[unlikely]] {      \
73
        null_map[i] = true;        \
74
    }
75
76
class Field;
77
class VExpr;
78
79
// Only use dispose the variadic argument
80
template <typename T>
81
auto has_variadic_argument_types(T&& arg) -> decltype(T::get_variadic_argument_types()) {};
82
void has_variadic_argument_types(...);
83
84
template <typename T>
85
concept HasGetVariadicArgumentTypesImpl = requires(T t) {
86
    { t.get_variadic_argument_types_impl() } -> std::same_as<DataTypes>;
87
};
88
89
bool have_null_column(const Block& block, const ColumnNumbers& args);
90
bool have_null_column(const ColumnsWithTypeAndName& args);
91
92
/// The simplest executable object.
93
/// Motivation:
94
///  * Prepare something heavy once before main execution loop instead of doing it for each block.
95
///  * Provide const interface for IFunctionBase (later).
96
class IPreparedFunction {
97
public:
98
100k
    virtual ~IPreparedFunction() = default;
99
100
    /// Get the main function name.
101
    virtual String get_name() const = 0;
102
103
    virtual Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
104
                           uint32_t result, size_t input_rows_count) const = 0;
105
};
106
107
using PreparedFunctionPtr = std::shared_ptr<IPreparedFunction>;
108
109
class PreparedFunctionImpl : public IPreparedFunction {
110
public:
111
    Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
112
                   uint32_t result, size_t input_rows_count) const final;
113
114
    /** If the function have non-zero number of arguments,
115
      *  and if all arguments are constant, that we could automatically provide default implementation:
116
      *  arguments are converted to ordinary columns with single value which is not const, then function is executed as usual,
117
      *  and then the result is converted to constant column.
118
      */
119
106k
    virtual bool use_default_implementation_for_constants() const { return true; }
120
121
    /** If use_default_implementation_for_nulls() is true, after execute the function,
122
      * whether need to replace the nested data of null data to the default value.
123
      * E.g. for binary arithmetic exprs, need return true to avoid false overflow.
124
      */
125
0
    virtual bool need_replace_null_data_to_default() const { return false; }
126
127
protected:
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
    /** Some arguments could remain constant during this implementation.
143
      * Every argument required const must write here and no checks elsewhere.
144
      */
145
0
    virtual ColumnNumbers get_arguments_that_are_always_constant() const { return {}; }
146
147
private:
148
    Status default_implementation_for_nulls(FunctionContext* context, Block& block,
149
                                            const ColumnNumbers& args, uint32_t result,
150
                                            size_t input_rows_count, bool* executed) const;
151
    Status default_implementation_for_constant_arguments(FunctionContext* context, Block& block,
152
                                                         const ColumnNumbers& args, uint32_t result,
153
                                                         size_t input_rows_count,
154
                                                         bool* executed) const;
155
    Status default_execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
156
                           uint32_t result, size_t input_rows_count) const;
157
    Status _execute_skipped_constant_deal(FunctionContext* context, Block& block,
158
                                          const ColumnNumbers& args, uint32_t result,
159
                                          size_t input_rows_count) const;
160
};
161
162
/// Function with known arguments and return type.
163
class IFunctionBase {
164
public:
165
115k
    virtual ~IFunctionBase() = default;
166
167
    /// Get the main function name.
168
    virtual String get_name() const = 0;
169
170
    virtual const DataTypes& get_argument_types() const = 0;
171
    virtual const DataTypePtr& get_return_type() const = 0;
172
173
    /// Do preparations and return executable.
174
    /// sample_block should contain data types of arguments and values of constants, if relevant.
175
    virtual PreparedFunctionPtr prepare(FunctionContext* context, const Block& sample_block,
176
                                        const ColumnNumbers& arguments, uint32_t result) const = 0;
177
178
    /// Override this when function need to store state in the `FunctionContext`, or do some
179
    /// preparation work according to information from `FunctionContext`.
180
70.0k
    virtual Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) {
181
70.0k
        return Status::OK();
182
70.0k
    }
183
184
    Status execute(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
185
97.8k
                   uint32_t result, size_t input_rows_count) const {
186
97.8k
        try {
187
97.8k
            return prepare(context, block, arguments, result)
188
97.8k
                    ->execute(context, block, arguments, result, input_rows_count);
189
97.8k
        } catch (const Exception& e) {
190
1
            return e.to_status();
191
1
        }
192
97.8k
    }
193
194
    virtual Status evaluate_inverted_index(
195
            const ColumnsWithTypeAndName& arguments,
196
            const std::vector<vectorized::IndexFieldNameAndTypePair>& data_type_with_names,
197
            std::vector<segment_v2::IndexIterator*> iterators, uint32_t num_rows,
198
            const InvertedIndexAnalyzerCtx* analyzer_ctx,
199
0
            segment_v2::InvertedIndexResultBitmap& bitmap_result) const {
200
0
        return Status::OK();
201
0
    }
202
203
    /// Do cleaning work when function is finished, i.e., release state variables in the
204
    /// `FunctionContext` which are registered in `prepare` phase.
205
50.9k
    virtual Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) {
206
50.9k
        return Status::OK();
207
50.9k
    }
208
209
    virtual bool is_use_default_implementation_for_constants() const = 0;
210
211
0
    virtual bool is_udf_function() const { return false; }
212
213
0
    virtual bool can_push_down_to_index() const { return false; }
214
215
0
    virtual bool is_blockable() const { return false; }
216
};
217
218
using FunctionBasePtr = std::shared_ptr<IFunctionBase>;
219
220
/// Creates IFunctionBase from argument types list.
221
class IFunctionBuilder {
222
public:
223
117k
    virtual ~IFunctionBuilder() = default;
224
225
    /// Get the main function name.
226
    virtual String get_name() const = 0;
227
228
    /// Override and return true if function could take different number of arguments.
229
    ///TODO: this function is not actually used now. but in check_number_of_arguments we still need it because for many
230
    /// functions we didn't set the correct 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
3
inline std::string get_types_string(const ColumnsWithTypeAndName& arguments) {
255
3
    std::string types;
256
3
    for (const auto& argument : arguments) {
257
2
        if (!types.empty()) {
258
1
            types += ", ";
259
1
        }
260
2
        types += argument.type->get_name();
261
2
    }
262
3
    return types;
263
3
}
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
98.5k
                          const DataTypePtr& return_type) const final {
271
98.5k
        if (skip_return_type_check()) {
272
84.2k
            return build_impl(arguments, return_type);
273
84.2k
        }
274
14.3k
        const DataTypePtr& func_return_type = get_return_type(arguments);
275
14.3k
        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.3k
        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.3k
              (return_type->is_nullable() && func_return_type->is_nullable() &&
288
14
               ((DataTypeNullable*)func_return_type.get())
289
9
                               ->get_nested_type()
290
9
                               ->get_primitive_type() == INVALID_TYPE) ||
291
14.3k
              is_date_or_datetime_or_decimal(return_type, func_return_type) ||
292
14.3k
              is_nested_type_date_or_datetime_or_decimal(return_type, func_return_type))) {
293
2
            throw doris::Exception(
294
2
                    ErrorCode::INTERNAL_ERROR,
295
2
                    "function return type check failed, function_name={}, "
296
2
                    "fe plan return type={},  be real return type={}, input_arguments={}",
297
2
                    get_name(), return_type->get_name(), func_return_type->get_name(),
298
2
                    get_types_string(arguments));
299
2
        }
300
14.3k
        return build_impl(arguments, return_type);
301
14.3k
    }
302
303
10.6k
    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
1.01k
    DataTypes get_variadic_argument_types() const override {
313
1.01k
        return get_variadic_argument_types_impl();
314
1.01k
    }
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.1k
    virtual DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const {
323
14.1k
        DataTypes data_types(arguments.size());
324
52.5k
        for (size_t i = 0; i < arguments.size(); ++i) {
325
38.4k
            data_types[i] = arguments[i].type;
326
38.4k
        }
327
14.1k
        return get_return_type_impl(data_types);
328
14.1k
    }
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
0
    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
    /// return a real function object to execute. called in build(...).
351
    virtual FunctionBasePtr build_impl(const ColumnsWithTypeAndName& arguments,
352
                                       const DataTypePtr& return_type) const = 0;
353
354
348
    virtual DataTypes get_variadic_argument_types_impl() const { return {}; }
355
356
private:
357
    bool is_date_or_datetime_or_decimal(const DataTypePtr& return_type,
358
                                        const DataTypePtr& func_return_type) const;
359
    bool is_nested_type_date_or_datetime_or_decimal(const DataTypePtr& return_type,
360
                                                    const DataTypePtr& func_return_type) const;
361
};
362
363
/// Previous function interface.
364
class IFunction : public std::enable_shared_from_this<IFunction>,
365
                  public FunctionBuilderImpl,
366
                  public IFunctionBase,
367
                  public PreparedFunctionImpl {
368
public:
369
    String get_name() const override = 0;
370
371
    /// Notice: We should not change the column in the block, because the column may be shared by multiple expressions or exec nodes.
372
    Status execute_impl(FunctionContext* context, Block& block, const ColumnNumbers& arguments,
373
                        uint32_t result, size_t input_rows_count) const override = 0;
374
375
    /// Override this functions to change default implementation behavior. See details in IMyFunction.
376
35.7k
    bool use_default_implementation_for_nulls() const override { return true; }
377
378
14.3k
    bool skip_return_type_check() const override { return false; }
379
380
8.78k
    bool need_replace_null_data_to_default() const override { return false; }
381
382
    /// all constancy check should use this function to do automatically
383
23.1k
    ColumnNumbers get_arguments_that_are_always_constant() const override { return {}; }
384
385
35
    bool is_use_default_implementation_for_constants() const override {
386
35
        return use_default_implementation_for_constants();
387
35
    }
388
389
    using PreparedFunctionImpl::execute;
390
    using FunctionBuilderImpl::get_return_type_impl;
391
    using FunctionBuilderImpl::get_variadic_argument_types_impl;
392
    using FunctionBuilderImpl::get_return_type;
393
394
    [[noreturn]] PreparedFunctionPtr prepare(FunctionContext* context,
395
                                             const Block& /*sample_block*/,
396
                                             const ColumnNumbers& /*arguments*/,
397
0
                                             uint32_t /*result*/) const final {
398
0
        throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR,
399
0
                               "prepare is not implemented for IFunction {}", get_name());
400
0
        __builtin_unreachable();
401
0
    }
402
403
26.5k
    Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) override {
404
26.5k
        return Status::OK();
405
26.5k
    }
406
407
0
    [[noreturn]] const DataTypes& get_argument_types() const final {
408
0
        throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR,
409
0
                               "get_argument_types is not implemented for IFunction {}",
410
0
                               get_name());
411
0
        __builtin_unreachable();
412
0
    }
413
414
0
    [[noreturn]] const DataTypePtr& get_return_type() const final {
415
0
        throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR,
416
0
                               "get_return_type is not implemented for IFunction {}", get_name());
417
0
        __builtin_unreachable();
418
0
    }
419
420
protected:
421
    FunctionBasePtr build_impl(const ColumnsWithTypeAndName& /*arguments*/,
422
0
                               const DataTypePtr& /*return_type*/) const final {
423
0
        throw doris::Exception(ErrorCode::NOT_IMPLEMENTED_ERROR,
424
0
                               "build_impl is not implemented for IFunction {}", get_name());
425
0
        __builtin_unreachable();
426
0
        return {};
427
0
    }
428
};
429
430
/*
431
 * when we register a function which didn't specify its base(i.e. inherited from IFunction), actually we use this as a wrapper.
432
 * it saves real implementation as `function`. 
433
*/
434
class DefaultFunction final : public IFunctionBase {
435
public:
436
    DefaultFunction(std::shared_ptr<IFunction> function_, DataTypes arguments_,
437
                    DataTypePtr return_type_)
438
14.3k
            : function(std::move(function_)),
439
14.3k
              arguments(std::move(arguments_)),
440
14.3k
              return_type(std::move(return_type_)) {}
441
442
0
    String get_name() const override { return function->get_name(); }
443
444
0
    const DataTypes& get_argument_types() const override { return arguments; }
445
1
    const DataTypePtr& get_return_type() const override { return return_type; }
446
447
    // return a default wrapper for IFunction.
448
    PreparedFunctionPtr prepare(FunctionContext* context, const Block& /*sample_block*/,
449
                                const ColumnNumbers& /*arguments*/,
450
14.2k
                                uint32_t /*result*/) const override {
451
14.2k
        return function;
452
14.2k
    }
453
454
28.2k
    Status open(FunctionContext* context, FunctionContext::FunctionStateScope scope) override {
455
28.2k
        return function->open(context, scope);
456
28.2k
    }
457
458
28.2k
    Status close(FunctionContext* context, FunctionContext::FunctionStateScope scope) override {
459
28.2k
        return function->close(context, scope);
460
28.2k
    }
461
462
    Status evaluate_inverted_index(
463
            const ColumnsWithTypeAndName& args,
464
            const std::vector<vectorized::IndexFieldNameAndTypePair>& data_type_with_names,
465
            std::vector<segment_v2::IndexIterator*> iterators, uint32_t num_rows,
466
            const InvertedIndexAnalyzerCtx* analyzer_ctx,
467
0
            segment_v2::InvertedIndexResultBitmap& bitmap_result) const override {
468
0
        return function->evaluate_inverted_index(args, data_type_with_names, iterators, num_rows,
469
0
                                                 analyzer_ctx, bitmap_result);
470
0
    }
471
472
35
    bool is_use_default_implementation_for_constants() const override {
473
35
        return function->is_use_default_implementation_for_constants();
474
35
    }
475
476
0
    bool can_push_down_to_index() const override { return function->can_push_down_to_index(); }
477
478
0
    bool is_blockable() const override { return function->is_blockable(); }
479
480
private:
481
    std::shared_ptr<IFunction> function;
482
    DataTypes arguments;
483
    DataTypePtr return_type;
484
};
485
486
struct simple_function_creator_without_type0 {
487
    template <typename AggregateFunctionTemplate, typename... TArgs>
488
0
    static std::shared_ptr<IFunction> create(const DataTypePtr& result_type, TArgs&&... args) {
489
0
        std::unique_ptr<IFunction> result(std::make_unique<AggregateFunctionTemplate>(
490
0
                result_type, std::forward<TArgs>(args)...));
491
0
        return std::shared_ptr<IFunction>(result.release());
492
0
    }
Unexecuted instantiation: _ZN5doris10vectorized37simple_function_creator_without_type06createINS0_25FunctionArrayAggDecimalV3INS0_27ArrayAggregateImplDecimalV3ILNS0_18AggregateOperationE2ELNS_13PrimitiveTypeE30EEENS0_12NameArraySumEEEJEEESt10shared_ptrINS0_9IFunctionEERKSA_IKNS0_9IDataTypeEEDpOT0_
Unexecuted instantiation: _ZN5doris10vectorized37simple_function_creator_without_type06createINS0_25FunctionArrayAggDecimalV3INS0_27ArrayAggregateImplDecimalV3ILNS0_18AggregateOperationE2ELNS_13PrimitiveTypeE35EEENS0_12NameArraySumEEEJEEESt10shared_ptrINS0_9IFunctionEERKSA_IKNS0_9IDataTypeEEDpOT0_
Unexecuted instantiation: _ZN5doris10vectorized37simple_function_creator_without_type06createINS0_25FunctionArrayAggDecimalV3INS0_27ArrayAggregateImplDecimalV3ILNS0_18AggregateOperationE3ELNS_13PrimitiveTypeE30EEENS0_16NameArrayAverageEEEJEEESt10shared_ptrINS0_9IFunctionEERKSA_IKNS0_9IDataTypeEEDpOT0_
Unexecuted instantiation: _ZN5doris10vectorized37simple_function_creator_without_type06createINS0_25FunctionArrayAggDecimalV3INS0_27ArrayAggregateImplDecimalV3ILNS0_18AggregateOperationE3ELNS_13PrimitiveTypeE35EEENS0_16NameArrayAverageEEEJEEESt10shared_ptrINS0_9IFunctionEERKSA_IKNS0_9IDataTypeEEDpOT0_
Unexecuted instantiation: _ZN5doris10vectorized37simple_function_creator_without_type06createINS0_25FunctionArrayAggDecimalV3INS0_27ArrayAggregateImplDecimalV3ILNS0_18AggregateOperationE4ELNS_13PrimitiveTypeE30EEENS0_16NameArrayProductEEEJEEESt10shared_ptrINS0_9IFunctionEERKSA_IKNS0_9IDataTypeEEDpOT0_
Unexecuted instantiation: _ZN5doris10vectorized37simple_function_creator_without_type06createINS0_25FunctionArrayAggDecimalV3INS0_27ArrayAggregateImplDecimalV3ILNS0_18AggregateOperationE4ELNS_13PrimitiveTypeE35EEENS0_16NameArrayProductEEEJEEESt10shared_ptrINS0_9IFunctionEERKSA_IKNS0_9IDataTypeEEDpOT0_
Unexecuted instantiation: _ZN5doris10vectorized37simple_function_creator_without_type06createINS0_19FunctionArrayCumSumILNS_13PrimitiveTypeE30EEEJEEESt10shared_ptrINS0_9IFunctionEERKS6_IKNS0_9IDataTypeEEDpOT0_
Unexecuted instantiation: _ZN5doris10vectorized37simple_function_creator_without_type06createINS0_19FunctionArrayCumSumILNS_13PrimitiveTypeE35EEEJEEESt10shared_ptrINS0_9IFunctionEERKS6_IKNS0_9IDataTypeEEDpOT0_
493
};
494
template <template <PrimitiveType> class FunctionTemplate>
495
struct SimpleFunctionCurryDirectWithResultType0 {
496
    template <PrimitiveType ResultType>
497
    using T = FunctionTemplate<ResultType>;
498
};
499
template <PrimitiveType... AllowedTypes>
500
struct simple_function_creator_with_result_type0 {
501
    template <typename Class, typename... TArgs>
502
    static std::shared_ptr<IFunction> create_base_with_result_type(const DataTypePtr& result_type,
503
0
                                                                   TArgs&&... args) {
504
0
        auto create = [&]<PrimitiveType ResultType>() {
505
0
            return simple_function_creator_without_type0::create<
506
0
                    typename Class::template T<ResultType>>(result_type,
507
0
                                                            std::forward<TArgs>(args)...);
508
0
        };
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_17ArraySumDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlTnS2_vE_clILS2_30EEEDav
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_17ArraySumDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlTnS2_vE_clILS2_35EEEDav
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_17ArrayAvgDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlTnS2_vE_clILS2_30EEEDav
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_17ArrayAvgDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlTnS2_vE_clILS2_35EEEDav
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_21ArrayProductDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlTnS2_vE_clILS2_30EEEDav
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_21ArrayProductDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlTnS2_vE_clILS2_35EEEDav
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_19FunctionArrayCumSumEEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlTnS2_vE_clILS2_30EEEDav
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_19FunctionArrayCumSumEEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlTnS2_vE_clILS2_35EEEDav
509
0
        std::shared_ptr<IFunction> result = nullptr;
510
0
        auto type = result_type->get_primitive_type();
511
512
0
        (
513
0
                [&] {
514
0
                    if (type == AllowedTypes) {
515
0
                        static_assert(AllowedTypes == TYPE_DECIMAL128I ||
516
0
                                      AllowedTypes == TYPE_DECIMAL256);
517
0
                        result = create.template operator()<AllowedTypes>();
518
0
                    }
519
0
                }(),
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_17ArraySumDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlvE0_clEv
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_17ArraySumDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlvE_clEv
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_17ArrayAvgDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlvE0_clEv
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_17ArrayAvgDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlvE_clEv
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_21ArrayProductDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlvE0_clEv
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_21ArrayProductDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlvE_clEv
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_19FunctionArrayCumSumEEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlvE0_clEv
Unexecuted instantiation: _ZZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_19FunctionArrayCumSumEEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_ENKUlvE_clEv
520
0
                ...);
521
522
0
        return result;
523
0
    }
Unexecuted instantiation: _ZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_17ArraySumDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_
Unexecuted instantiation: _ZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_17ArrayAvgDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_
Unexecuted instantiation: _ZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_21ArrayProductDecimalV3EEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_
Unexecuted instantiation: _ZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE28create_base_with_result_typeINS0_40SimpleFunctionCurryDirectWithResultType0INS0_19FunctionArrayCumSumEEEJEEESt10shared_ptrINS0_9IFunctionEERKS8_IKNS0_9IDataTypeEEDpOT0_
524
525
    // Create agg function with result type from FE.
526
    // Currently only used for decimalv3 sum and avg.
527
    template <template <PrimitiveType> class FunctionTemplate>
528
0
    static std::shared_ptr<IFunction> creator_with_result_type(const DataTypePtr& result_type) {
529
0
        return create_base_with_result_type<
530
0
                SimpleFunctionCurryDirectWithResultType0<FunctionTemplate>>(result_type);
531
0
    }
Unexecuted instantiation: _ZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE24creator_with_result_typeINS0_17ArraySumDecimalV3EEESt10shared_ptrINS0_9IFunctionEERKS6_IKNS0_9IDataTypeEE
Unexecuted instantiation: _ZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE24creator_with_result_typeINS0_17ArrayAvgDecimalV3EEESt10shared_ptrINS0_9IFunctionEERKS6_IKNS0_9IDataTypeEE
Unexecuted instantiation: _ZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE24creator_with_result_typeINS0_21ArrayProductDecimalV3EEESt10shared_ptrINS0_9IFunctionEERKS6_IKNS0_9IDataTypeEE
Unexecuted instantiation: _ZN5doris10vectorized41simple_function_creator_with_result_type0IJLNS_13PrimitiveTypeE30ELS2_35EEE24creator_with_result_typeINS0_19FunctionArrayCumSumEEESt10shared_ptrINS0_9IFunctionEERKS6_IKNS0_9IDataTypeEE
532
};
533
534
class DefaultFunctionBuilder : public FunctionBuilderImpl {
535
public:
536
    explicit DefaultFunctionBuilder(std::shared_ptr<IFunction> function_)
537
16.3k
            : function(std::move(function_)) {}
538
539
    // template <template <PrimitiveType> class FunctionTemplate>
540
    explicit DefaultFunctionBuilder(DataTypePtr return_type)
541
0
            : _return_type(std::move(return_type)) {}
542
543
    template <template <PrimitiveType> class FunctionTemplate>
544
0
    static FunctionBuilderPtr create_array_agg_function_decimalv3(DataTypePtr return_type) {
545
0
        auto builder = std::make_shared<DefaultFunctionBuilder>(return_type);
546
0
        DataTypePtr real_return_type;
547
        // for array_cum_sum, the return type is array,
548
        // so here should check nested type
549
0
        if (PrimitiveType::TYPE_ARRAY == return_type->get_primitive_type()) {
550
0
            const DataTypeArray* data_type_array =
551
0
                    static_cast<const DataTypeArray*>(remove_nullable(return_type).get());
552
0
            real_return_type = data_type_array->get_nested_type();
553
0
        } else {
554
0
            real_return_type = return_type;
555
0
        }
556
0
        builder->function =
557
0
                simple_function_creator_with_result_type0<TYPE_DECIMAL128I, TYPE_DECIMAL256>::
558
0
                        creator_with_result_type<FunctionTemplate>(real_return_type);
559
0
        return builder;
560
0
    }
Unexecuted instantiation: _ZN5doris10vectorized22DefaultFunctionBuilder35create_array_agg_function_decimalv3INS0_17ArraySumDecimalV3EEESt10shared_ptrINS0_16IFunctionBuilderEES4_IKNS0_9IDataTypeEE
Unexecuted instantiation: _ZN5doris10vectorized22DefaultFunctionBuilder35create_array_agg_function_decimalv3INS0_17ArrayAvgDecimalV3EEESt10shared_ptrINS0_16IFunctionBuilderEES4_IKNS0_9IDataTypeEE
Unexecuted instantiation: _ZN5doris10vectorized22DefaultFunctionBuilder35create_array_agg_function_decimalv3INS0_21ArrayProductDecimalV3EEESt10shared_ptrINS0_16IFunctionBuilderEES4_IKNS0_9IDataTypeEE
Unexecuted instantiation: _ZN5doris10vectorized22DefaultFunctionBuilder35create_array_agg_function_decimalv3INS0_19FunctionArrayCumSumEEESt10shared_ptrINS0_16IFunctionBuilderEES4_IKNS0_9IDataTypeEE
561
562
14.3k
    void check_number_of_arguments(size_t number_of_arguments) const override {
563
14.3k
        function->check_number_of_arguments(number_of_arguments);
564
14.3k
    }
565
566
492
    String get_name() const override { return function->get_name(); }
567
985
    bool is_variadic() const override { return function->is_variadic(); }
568
0
    size_t get_number_of_arguments() const override { return function->get_number_of_arguments(); }
569
570
0
    ColumnNumbers get_arguments_that_are_always_constant() const override {
571
0
        return function->get_arguments_that_are_always_constant();
572
0
    }
573
574
protected:
575
0
    DataTypePtr get_return_type_impl(const DataTypes& arguments) const override {
576
0
        return function->get_return_type_impl(arguments);
577
0
    }
578
14.3k
    DataTypePtr get_return_type_impl(const ColumnsWithTypeAndName& arguments) const override {
579
14.3k
        return function->get_return_type_impl(arguments);
580
14.3k
    }
581
582
14.3k
    bool use_default_implementation_for_nulls() const override {
583
14.3k
        return function->use_default_implementation_for_nulls();
584
14.3k
    }
585
586
14.3k
    bool skip_return_type_check() const override { return function->skip_return_type_check(); }
587
588
0
    bool need_replace_null_data_to_default() const override {
589
0
        return function->need_replace_null_data_to_default();
590
0
    }
591
592
    FunctionBasePtr build_impl(const ColumnsWithTypeAndName& arguments,
593
14.3k
                               const DataTypePtr& return_type) const override {
594
14.3k
        DataTypes data_types(arguments.size());
595
53.1k
        for (size_t i = 0; i < arguments.size(); ++i) {
596
38.8k
            data_types[i] = arguments[i].type;
597
38.8k
        }
598
14.3k
        return std::make_shared<DefaultFunction>(function, data_types, return_type);
599
14.3k
    }
600
601
1.01k
    DataTypes get_variadic_argument_types_impl() const override {
602
1.01k
        return function->get_variadic_argument_types_impl();
603
1.01k
    }
604
605
private:
606
    std::shared_ptr<IFunction> function;
607
    DataTypePtr _return_type;
608
};
609
610
using FunctionPtr = std::shared_ptr<IFunction>;
611
/** Return ColumnNullable of src, with null map as OR-ed null maps of args columns in blocks.
612
  * Or ColumnConst(ColumnNullable) if the result is always NULL or if the result is constant and always not NULL.
613
  */
614
ColumnPtr wrap_in_nullable(const ColumnPtr& src, const Block& block, const ColumnNumbers& args,
615
                           size_t input_rows_count);
616
617
} // namespace doris::vectorized