Coverage Report

Created: 2025-04-27 17:16

/root/doris/be/src/vec/exprs/vexpr.h
Line
Count
Source (jump to first uncovered line)
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <gen_cpp/Exprs_types.h>
21
#include <gen_cpp/Opcodes_types.h>
22
#include <gen_cpp/Types_types.h>
23
#include <glog/logging.h>
24
25
#include <cstddef>
26
#include <cstdint>
27
#include <memory>
28
#include <ostream>
29
#include <string>
30
#include <utility>
31
#include <vector>
32
33
#include "common/status.h"
34
#include "olap/rowset/segment_v2/inverted_index_reader.h"
35
#include "runtime/define_primitive_type.h"
36
#include "runtime/large_int_value.h"
37
#include "runtime/types.h"
38
#include "udf/udf.h"
39
#include "vec/aggregate_functions/aggregate_function.h"
40
#include "vec/columns/column.h"
41
#include "vec/core/block.h"
42
#include "vec/core/column_with_type_and_name.h"
43
#include "vec/core/types.h"
44
#include "vec/core/wide_integer.h"
45
#include "vec/data_types/data_type.h"
46
#include "vec/data_types/data_type_ipv6.h"
47
#include "vec/exprs/vexpr_fwd.h"
48
#include "vec/functions/function.h"
49
50
namespace doris {
51
class BitmapFilterFuncBase;
52
class BloomFilterFuncBase;
53
class HybridSetBase;
54
class ObjectPool;
55
class RowDescriptor;
56
class RuntimeState;
57
58
namespace vectorized {
59
#include "common/compile_check_begin.h"
60
61
#define RETURN_IF_ERROR_OR_PREPARED(stmt) \
62
275k
    if (_prepared) {                      \
63
0
        return Status::OK();              \
64
0
    }                                     \
65
275k
    _prepared = true;                     \
66
275k
    RETURN_IF_ERROR(stmt);
67
68
// VExpr should be used as shared pointer because it will be passed between classes
69
// like runtime filter to scan node, or from scannode to scanner. We could not make sure
70
// the relatioinship between threads and classes.
71
class VExpr {
72
public:
73
    // resize inserted param column to make sure column size equal to block.rows() and return param column index
74
    // keep return type same with block::columns()
75
80
    static uint32_t insert_param(Block* block, ColumnWithTypeAndName&& elem, size_t size) {
76
        // usually elem.column always is const column, so we just clone it.
77
80
        elem.column = elem.column->clone_resized(size);
78
80
        block->insert(std::move(elem));
79
        // just inserted. so no need to check underflow.
80
80
        return block->columns() - 1;
81
80
    }
82
83
    static bool is_acting_on_a_slot(const VExpr& expr);
84
85
    VExpr(const TExprNode& node);
86
    VExpr(const VExpr& vexpr);
87
    VExpr(TypeDescriptor type, bool is_slotref, bool is_nullable);
88
    // only used for test
89
578
    VExpr() = default;
90
429k
    virtual ~VExpr() = default;
91
92
    virtual const std::string& expr_name() const = 0;
93
0
    virtual std::string expr_label() { return ""; }
94
95
    /// Initializes this expr instance for execution. This does not include initializing
96
    /// state in the VExprContext; 'context' should only be used to register a
97
    /// FunctionContext via RegisterFunctionContext().
98
    ///
99
    /// Subclasses overriding this function should call VExpr::Prepare() to recursively call
100
    /// Prepare() on the expr tree
101
    /// row_desc used in vslot_ref and some subclass to specify column
102
    virtual Status prepare(RuntimeState* state, const RowDescriptor& row_desc,
103
                           VExprContext* context);
104
105
    /// Initializes 'context' for execution. If scope if FRAGMENT_LOCAL, both fragment- and
106
    /// thread-local state should be initialized. Otherwise, if scope is THREAD_LOCAL, only
107
    /// thread-local state should be initialized.
108
    //
109
    /// Subclasses overriding this function should call VExpr::Open() to recursively call
110
    /// Open() on the expr tree
111
    virtual Status open(RuntimeState* state, VExprContext* context,
112
                        FunctionContext::FunctionStateScope scope);
113
114
    // before execute, check if expr has been parepared+opened.
115
0
    [[maybe_unused]] Status ready_status() const {
116
0
        if (_prepare_finished && _open_finished) {
117
0
            return Status::OK();
118
0
        }
119
0
        return Status::InternalError(expr_name() + " is not ready when execute");
120
0
    }
121
122
    virtual Status execute(VExprContext* context, Block* block, int* result_column_id) = 0;
123
124
    // execute current expr with inverted index to filter block. Given a roaring bitmap of match rows
125
0
    virtual Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) {
126
0
        return Status::OK();
127
0
    }
128
129
    Status _evaluate_inverted_index(VExprContext* context, const FunctionBasePtr& function,
130
                                    uint32_t segment_num_rows);
131
132
    virtual size_t estimate_memory(const size_t rows);
133
134
    // Only the 4th parameter is used in the runtime filter. In and MinMax need overwrite the
135
    // interface
136
    virtual Status execute_runtime_fitler(VExprContext* context, Block* block,
137
0
                                          int* result_column_id, ColumnNumbers& args) {
138
0
        return execute(context, block, result_column_id);
139
0
    };
140
141
    /// Subclasses overriding this function should call VExpr::Close().
142
    //
143
    /// If scope if FRAGMENT_LOCAL, both fragment- and thread-local state should be torn
144
    /// down. Otherwise, if scope is THREAD_LOCAL, only thread-local state should be torn
145
    /// down.
146
    virtual void close(VExprContext* context, FunctionContext::FunctionStateScope scope);
147
148
960k
    DataTypePtr& data_type() { return _data_type; }
149
150
562
    TypeDescriptor type() { return _type; }
151
152
79
    bool is_slot_ref() const { return _node_type == TExprNodeType::SLOT_REF; }
153
154
0
    bool is_column_ref() const { return _node_type == TExprNodeType::COLUMN_REF; }
155
156
0
    virtual bool is_literal() const { return false; }
157
158
286
    TExprNodeType::type node_type() const { return _node_type; }
159
160
115
    TExprOpcode::type op() const { return _opcode; }
161
162
193
    void add_child(const VExprSPtr& expr) { _children.push_back(expr); }
163
0
    VExprSPtr get_child(uint16_t i) const { return _children[i]; }
164
    // Expr's children number is restricted by org.apache.doris.common.Config#expr_children_limit, 10000 default. and strongly not recommend to change.
165
    // There's little to worry about it. uint16 is enough.
166
16
    uint16_t get_num_children() const { return static_cast<uint16_t>(_children.size()); }
167
168
34
    virtual bool is_rf_wrapper() const {
169
34
        return std::ranges::any_of(_children.begin(), _children.end(),
170
34
                                   [](VExprSPtr child) { return child->is_rf_wrapper(); });
171
34
    }
172
173
0
    virtual void do_judge_selectivity(uint64_t filter_rows, uint64_t input_rows) {
174
0
        for (auto child : _children) {
175
0
            child->do_judge_selectivity(filter_rows, input_rows);
176
0
        }
177
0
    }
178
179
    static Status create_expr_tree(const TExpr& texpr, VExprContextSPtr& ctx);
180
181
    static Status create_expr_trees(const std::vector<TExpr>& texprs, VExprContextSPtrs& ctxs);
182
183
    static Status prepare(const VExprContextSPtrs& ctxs, RuntimeState* state,
184
                          const RowDescriptor& row_desc);
185
186
    static Status open(const VExprContextSPtrs& ctxs, RuntimeState* state);
187
188
    static Status clone_if_not_exists(const VExprContextSPtrs& ctxs, RuntimeState* state,
189
                                      VExprContextSPtrs& new_ctxs);
190
191
47
    bool is_nullable() const { return _data_type->is_nullable(); }
192
193
0
    PrimitiveType result_type() const { return _type.type; }
194
195
    static Status create_expr(const TExprNode& expr_node, VExprSPtr& expr);
196
197
    static Status create_tree_from_thrift(const std::vector<TExprNode>& nodes, int* node_idx,
198
                                          VExprSPtr& root_expr, VExprContextSPtr& ctx);
199
200
    static Status check_expr_output_type(const VExprContextSPtrs& ctxs,
201
                                         const RowDescriptor& output_row_desc);
202
656
    virtual const VExprSPtrs& children() const { return _children; }
203
0
    void set_children(const VExprSPtrs& children) { _children = children; }
204
0
    void set_children(VExprSPtrs&& children) { _children = std::move(children); }
205
    virtual std::string debug_string() const;
206
    static std::string debug_string(const VExprSPtrs& exprs);
207
    static std::string debug_string(const VExprContextSPtrs& ctxs);
208
209
0
    void set_getting_const_col(bool val = true) { _getting_const_col = val; }
210
211
19
    bool is_and_expr() const { return _fn.name.function_name == "and"; }
212
213
0
    virtual bool is_compound_predicate() const { return false; }
214
215
28
    const TFunction& fn() const { return _fn; }
216
217
    /// Returns true if expr doesn't contain slotrefs, i.e., can be evaluated
218
    /// with get_value(NULL). The default implementation returns true if all of
219
    /// the children are constant.
220
    virtual bool is_constant() const;
221
222
    /// If this expr is constant, evaluates the expr with no input row argument and returns
223
    /// the output. Returns nullptr if the argument is not constant. The returned ColumnPtr is
224
    /// owned by this expr. This should only be called after Open() has been called on this
225
    /// expr.
226
    MOCK_FUNCTION Status get_const_col(VExprContext* context,
227
                                       std::shared_ptr<ColumnPtrWrapper>* column_wrapper);
228
229
18
    int fn_context_index() const { return _fn_context_index; }
230
231
83
    static VExprSPtr expr_without_cast(const VExprSPtr& expr) {
232
83
        if (expr->node_type() == TExprNodeType::CAST_EXPR) {
233
0
            return expr_without_cast(expr->_children[0]);
234
0
        }
235
83
        return expr;
236
83
    }
237
238
    // If this expr is a RuntimeFilterWrapper, this method will return an underlying rf expression
239
19
    virtual VExprSPtr get_impl() const { return {}; }
240
241
    // If this expr is a BloomPredicate, this method will return a BloomFilterFunc
242
0
    virtual std::shared_ptr<BloomFilterFuncBase> get_bloom_filter_func() const {
243
0
        throw Exception(Status::FatalError(
244
0
                "Method 'get_bloom_filter_func()' is not supported in expression: {}",
245
0
                this->debug_string()));
246
0
    }
247
248
10
    virtual std::shared_ptr<HybridSetBase> get_set_func() const { return nullptr; }
249
250
    // If this expr is a BitmapPredicate, this method will return a BitmapFilterFunc
251
0
    virtual std::shared_ptr<BitmapFilterFuncBase> get_bitmap_filter_func() const {
252
0
        throw Exception(Status::FatalError(
253
0
                "Method 'get_bitmap_filter_func()' is not supported in expression: {}",
254
0
                this->debug_string()));
255
0
    }
256
257
    // fast_execute can direct copy expr filter result which build by apply index in segment_iterator
258
    bool fast_execute(doris::vectorized::VExprContext* context, doris::vectorized::Block* block,
259
                      int* result_column_id);
260
261
0
    virtual bool can_push_down_to_index() const { return false; }
262
    virtual bool equals(const VExpr& other);
263
0
    void set_index_unique_id(uint32_t index_unique_id) { _index_unique_id = index_unique_id; }
264
0
    uint32_t index_unique_id() const { return _index_unique_id; }
265
266
19
    virtual void collect_slot_column_ids(std::set<int>& column_ids) const {
267
22
        for (auto child : _children) {
268
22
            child->collect_slot_column_ids(column_ids);
269
22
        }
270
19
    }
271
272
protected:
273
    /// Simple debug string that provides no expr subclass-specific information
274
0
    std::string debug_string(const std::string& expr_name) const {
275
0
        std::stringstream out;
276
0
        out << expr_name << "(" << VExpr::debug_string() << ")";
277
0
        return out.str();
278
0
    }
279
280
76
    std::string get_child_names() {
281
76
        std::string res;
282
111
        for (auto child : _children) {
283
111
            if (!res.empty()) {
284
42
                res += ", ";
285
42
            }
286
111
            res += child->expr_name();
287
111
        }
288
76
        return res;
289
76
    }
290
291
7
    bool is_const_and_have_executed() { return (is_constant() && (_constant_col != nullptr)); }
292
293
    Status get_result_from_const(vectorized::Block* block, const std::string& expr_name,
294
                                 int* result_column_id);
295
296
    Status check_constant(const Block& block, ColumnNumbers arguments) const;
297
298
    /// Helper function that calls ctx->register(), sets fn_context_index_, and returns the
299
    /// registered FunctionContext
300
    void register_function_context(RuntimeState* state, VExprContext* context);
301
302
    /// Helper function to initialize function context, called in `open` phase of VExpr:
303
    /// 1. Set constant columns result of function arguments.
304
    /// 2. Call function's prepare() to initialize function state, fragment-local or
305
    /// thread-local according the input `FunctionStateScope` argument.
306
    Status init_function_context(RuntimeState* state, VExprContext* context,
307
                                 FunctionContext::FunctionStateScope scope,
308
                                 const FunctionBasePtr& function) const;
309
310
    /// Helper function to close function context, fragment-local or thread-local according
311
    /// the input `FunctionStateScope` argument. Called in `close` phase of VExpr.
312
    void close_function_context(VExprContext* context, FunctionContext::FunctionStateScope scope,
313
                                const FunctionBasePtr& function) const;
314
315
    TExprNodeType::type _node_type;
316
    // Used to check what opcode
317
    TExprOpcode::type _opcode;
318
    TypeDescriptor _type;
319
    DataTypePtr _data_type;
320
    VExprSPtrs _children; // in few hundreds
321
    TFunction _fn;
322
323
    /// Index to pass to ExprContext::fn_context() to retrieve this expr's FunctionContext.
324
    /// Set in RegisterFunctionContext(). -1 if this expr does not need a FunctionContext and
325
    /// doesn't call RegisterFunctionContext().
326
    int _fn_context_index = -1;
327
328
    // If this expr is constant, this will store and cache the value generated by
329
    // get_const_col()
330
    std::shared_ptr<ColumnPtrWrapper> _constant_col;
331
    bool _prepared = false; // for base class VExpr
332
    bool _getting_const_col =
333
            false; // if true, current execute() is in prepare() (that is, can't check _prepared)
334
    // for concrete classes
335
    bool _prepare_finished = false;
336
    bool _open_finished = false;
337
338
    // ensuring uniqueness during index traversal
339
    uint32_t _index_unique_id = 0;
340
    bool _enable_inverted_index_query = true;
341
};
342
343
} // namespace vectorized
344
345
// NOLINTBEGIN(readability-function-size)
346
template <PrimitiveType T>
347
Status create_texpr_literal_node(const void* data, TExprNode* node, int precision = 0,
348
5
                                 int scale = 0) {
349
5
    if constexpr (T == TYPE_BOOLEAN) {
350
5
        const auto* origin_value = reinterpret_cast<const bool*>(data);
351
5
        TBoolLiteral boolLiteral;
352
5
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
353
5
        boolLiteral.__set_value(*origin_value);
354
5
        (*node).__set_bool_literal(boolLiteral);
355
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
356
5
    } else if constexpr (T == TYPE_TINYINT) {
357
5
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
358
5
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
359
5
        TIntLiteral intLiteral;
360
5
        intLiteral.__set_value(*origin_value);
361
5
        (*node).__set_int_literal(intLiteral);
362
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
363
5
    } else if constexpr (T == TYPE_SMALLINT) {
364
5
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
365
5
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
366
5
        TIntLiteral intLiteral;
367
5
        intLiteral.__set_value(*origin_value);
368
5
        (*node).__set_int_literal(intLiteral);
369
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
370
5
    } else if constexpr (T == TYPE_INT) {
371
0
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
372
0
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
373
0
        TIntLiteral intLiteral;
374
0
        intLiteral.__set_value(*origin_value);
375
0
        (*node).__set_int_literal(intLiteral);
376
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
377
0
    } else if constexpr (T == TYPE_BIGINT) {
378
0
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
379
0
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
380
0
        TIntLiteral intLiteral;
381
0
        intLiteral.__set_value(*origin_value);
382
0
        (*node).__set_int_literal(intLiteral);
383
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
384
0
    } else if constexpr (T == TYPE_LARGEINT) {
385
0
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
386
0
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
387
0
        TLargeIntLiteral large_int_literal;
388
0
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
389
0
        (*node).__set_large_int_literal(large_int_literal);
390
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
391
0
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME) || (T == TYPE_TIMEV2)) {
392
0
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
393
0
        TDateLiteral date_literal;
394
0
        char convert_buffer[30];
395
0
        origin_value->to_string(convert_buffer);
396
0
        date_literal.__set_value(convert_buffer);
397
0
        (*node).__set_date_literal(date_literal);
398
0
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
399
0
        if (origin_value->type() == TimeType::TIME_DATE) {
400
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
401
0
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
402
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
403
0
        } else if (origin_value->type() == TimeType::TIME_TIME) {
404
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2));
405
0
        }
406
0
    } else if constexpr (T == TYPE_DATEV2) {
407
0
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
408
0
        TDateLiteral date_literal;
409
0
        char convert_buffer[30];
410
0
        origin_value->to_string(convert_buffer);
411
0
        date_literal.__set_value(convert_buffer);
412
0
        (*node).__set_date_literal(date_literal);
413
0
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
414
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
415
0
    } else if constexpr (T == TYPE_DATETIMEV2) {
416
0
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
417
0
        TDateLiteral date_literal;
418
0
        char convert_buffer[30];
419
0
        origin_value->to_string(convert_buffer, scale);
420
0
        date_literal.__set_value(convert_buffer);
421
0
        (*node).__set_date_literal(date_literal);
422
0
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
423
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
424
0
    } else if constexpr (T == TYPE_DECIMALV2) {
425
0
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
426
0
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
427
0
        TDecimalLiteral decimal_literal;
428
0
        decimal_literal.__set_value(origin_value->to_string());
429
0
        (*node).__set_decimal_literal(decimal_literal);
430
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
431
0
    } else if constexpr (T == TYPE_DECIMAL32) {
432
0
        const auto* origin_value = reinterpret_cast<const vectorized::Decimal<int32_t>*>(data);
433
0
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
434
0
        TDecimalLiteral decimal_literal;
435
0
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
436
0
        (*node).__set_decimal_literal(decimal_literal);
437
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
438
0
    } else if constexpr (T == TYPE_DECIMAL64) {
439
0
        const auto* origin_value = reinterpret_cast<const vectorized::Decimal<int64_t>*>(data);
440
0
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
441
0
        TDecimalLiteral decimal_literal;
442
0
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
443
0
        (*node).__set_decimal_literal(decimal_literal);
444
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
445
0
    } else if constexpr (T == TYPE_DECIMAL128I) {
446
0
        const auto* origin_value = reinterpret_cast<const vectorized::Decimal<int128_t>*>(data);
447
0
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
448
0
        TDecimalLiteral decimal_literal;
449
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
450
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
451
        // final min value of the MinMax RF if the fragment instance has no data.
452
        // Need to truncate the value to the right precision and scale here, to avoid
453
        // error when casting string back to decimal later.
454
        // TODO: this is a temporary solution, the best solution is to produce the
455
        // right min max value at the producer side.
456
0
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
457
0
        (*node).__set_decimal_literal(decimal_literal);
458
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
459
0
    } else if constexpr (T == TYPE_DECIMAL256) {
460
0
        const auto* origin_value = reinterpret_cast<const vectorized::Decimal<wide::Int256>*>(data);
461
0
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
462
0
        TDecimalLiteral decimal_literal;
463
0
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
464
0
        (*node).__set_decimal_literal(decimal_literal);
465
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
466
0
    } else if constexpr (T == TYPE_FLOAT) {
467
0
        const auto* origin_value = reinterpret_cast<const float*>(data);
468
0
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
469
0
        TFloatLiteral float_literal;
470
0
        float_literal.__set_value(*origin_value);
471
0
        (*node).__set_float_literal(float_literal);
472
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
473
0
    } else if constexpr (T == TYPE_DOUBLE) {
474
0
        const auto* origin_value = reinterpret_cast<const double*>(data);
475
0
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
476
0
        TFloatLiteral float_literal;
477
0
        float_literal.__set_value(*origin_value);
478
0
        (*node).__set_float_literal(float_literal);
479
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
480
0
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
481
0
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
482
0
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
483
0
        TStringLiteral string_literal;
484
0
        string_literal.__set_value(*origin_value);
485
0
        (*node).__set_string_literal(string_literal);
486
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
487
0
    } else if constexpr (T == TYPE_IPV4) {
488
0
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
489
0
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
490
0
        TIPv4Literal literal;
491
0
        literal.__set_value(*origin_value);
492
0
        (*node).__set_ipv4_literal(literal);
493
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
494
0
    } else if constexpr (T == TYPE_IPV6) {
495
0
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
496
0
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
497
0
        TIPv6Literal literal;
498
0
        literal.__set_value(vectorized::DataTypeIPv6::to_string(*origin_value));
499
0
        (*node).__set_ipv6_literal(literal);
500
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
501
0
    } else {
502
5
        return Status::InvalidArgument("Invalid argument type!");
503
5
    }
504
5
    return Status::OK();
505
5
}
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE2EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE3EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE4EEENS_6StatusEPKvPNS_9TExprNodeEii
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE5EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
348
5
                                 int scale = 0) {
349
5
    if constexpr (T == TYPE_BOOLEAN) {
350
5
        const auto* origin_value = reinterpret_cast<const bool*>(data);
351
5
        TBoolLiteral boolLiteral;
352
5
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
353
5
        boolLiteral.__set_value(*origin_value);
354
5
        (*node).__set_bool_literal(boolLiteral);
355
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
356
5
    } else if constexpr (T == TYPE_TINYINT) {
357
5
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
358
5
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
359
5
        TIntLiteral intLiteral;
360
5
        intLiteral.__set_value(*origin_value);
361
5
        (*node).__set_int_literal(intLiteral);
362
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
363
5
    } else if constexpr (T == TYPE_SMALLINT) {
364
5
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
365
5
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
366
5
        TIntLiteral intLiteral;
367
5
        intLiteral.__set_value(*origin_value);
368
5
        (*node).__set_int_literal(intLiteral);
369
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
370
5
    } else if constexpr (T == TYPE_INT) {
371
5
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
372
5
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
373
5
        TIntLiteral intLiteral;
374
5
        intLiteral.__set_value(*origin_value);
375
5
        (*node).__set_int_literal(intLiteral);
376
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
377
5
    } else if constexpr (T == TYPE_BIGINT) {
378
5
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
379
5
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
380
5
        TIntLiteral intLiteral;
381
5
        intLiteral.__set_value(*origin_value);
382
5
        (*node).__set_int_literal(intLiteral);
383
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
384
5
    } else if constexpr (T == TYPE_LARGEINT) {
385
5
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
386
5
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
387
5
        TLargeIntLiteral large_int_literal;
388
5
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
389
5
        (*node).__set_large_int_literal(large_int_literal);
390
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
391
5
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME) || (T == TYPE_TIMEV2)) {
392
5
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
393
5
        TDateLiteral date_literal;
394
5
        char convert_buffer[30];
395
5
        origin_value->to_string(convert_buffer);
396
5
        date_literal.__set_value(convert_buffer);
397
5
        (*node).__set_date_literal(date_literal);
398
5
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
399
5
        if (origin_value->type() == TimeType::TIME_DATE) {
400
5
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
401
5
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
402
5
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
403
5
        } else if (origin_value->type() == TimeType::TIME_TIME) {
404
5
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2));
405
5
        }
406
5
    } else if constexpr (T == TYPE_DATEV2) {
407
5
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
408
5
        TDateLiteral date_literal;
409
5
        char convert_buffer[30];
410
5
        origin_value->to_string(convert_buffer);
411
5
        date_literal.__set_value(convert_buffer);
412
5
        (*node).__set_date_literal(date_literal);
413
5
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
414
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
415
5
    } else if constexpr (T == TYPE_DATETIMEV2) {
416
5
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
417
5
        TDateLiteral date_literal;
418
5
        char convert_buffer[30];
419
5
        origin_value->to_string(convert_buffer, scale);
420
5
        date_literal.__set_value(convert_buffer);
421
5
        (*node).__set_date_literal(date_literal);
422
5
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
423
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
424
5
    } else if constexpr (T == TYPE_DECIMALV2) {
425
5
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
426
5
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
427
5
        TDecimalLiteral decimal_literal;
428
5
        decimal_literal.__set_value(origin_value->to_string());
429
5
        (*node).__set_decimal_literal(decimal_literal);
430
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
431
5
    } else if constexpr (T == TYPE_DECIMAL32) {
432
5
        const auto* origin_value = reinterpret_cast<const vectorized::Decimal<int32_t>*>(data);
433
5
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
434
5
        TDecimalLiteral decimal_literal;
435
5
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
436
5
        (*node).__set_decimal_literal(decimal_literal);
437
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
438
5
    } else if constexpr (T == TYPE_DECIMAL64) {
439
5
        const auto* origin_value = reinterpret_cast<const vectorized::Decimal<int64_t>*>(data);
440
5
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
441
5
        TDecimalLiteral decimal_literal;
442
5
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
443
5
        (*node).__set_decimal_literal(decimal_literal);
444
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
445
5
    } else if constexpr (T == TYPE_DECIMAL128I) {
446
5
        const auto* origin_value = reinterpret_cast<const vectorized::Decimal<int128_t>*>(data);
447
5
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
448
5
        TDecimalLiteral decimal_literal;
449
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
450
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
451
        // final min value of the MinMax RF if the fragment instance has no data.
452
        // Need to truncate the value to the right precision and scale here, to avoid
453
        // error when casting string back to decimal later.
454
        // TODO: this is a temporary solution, the best solution is to produce the
455
        // right min max value at the producer side.
456
5
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
457
5
        (*node).__set_decimal_literal(decimal_literal);
458
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
459
5
    } else if constexpr (T == TYPE_DECIMAL256) {
460
5
        const auto* origin_value = reinterpret_cast<const vectorized::Decimal<wide::Int256>*>(data);
461
5
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
462
5
        TDecimalLiteral decimal_literal;
463
5
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
464
5
        (*node).__set_decimal_literal(decimal_literal);
465
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
466
5
    } else if constexpr (T == TYPE_FLOAT) {
467
5
        const auto* origin_value = reinterpret_cast<const float*>(data);
468
5
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
469
5
        TFloatLiteral float_literal;
470
5
        float_literal.__set_value(*origin_value);
471
5
        (*node).__set_float_literal(float_literal);
472
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
473
5
    } else if constexpr (T == TYPE_DOUBLE) {
474
5
        const auto* origin_value = reinterpret_cast<const double*>(data);
475
5
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
476
5
        TFloatLiteral float_literal;
477
5
        float_literal.__set_value(*origin_value);
478
5
        (*node).__set_float_literal(float_literal);
479
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
480
5
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
481
5
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
482
5
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
483
5
        TStringLiteral string_literal;
484
5
        string_literal.__set_value(*origin_value);
485
5
        (*node).__set_string_literal(string_literal);
486
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
487
5
    } else if constexpr (T == TYPE_IPV4) {
488
5
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
489
5
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
490
5
        TIPv4Literal literal;
491
5
        literal.__set_value(*origin_value);
492
5
        (*node).__set_ipv4_literal(literal);
493
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
494
5
    } else if constexpr (T == TYPE_IPV6) {
495
5
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
496
5
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
497
5
        TIPv6Literal literal;
498
5
        literal.__set_value(vectorized::DataTypeIPv6::to_string(*origin_value));
499
5
        (*node).__set_ipv6_literal(literal);
500
5
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
501
5
    } else {
502
5
        return Status::InvalidArgument("Invalid argument type!");
503
5
    }
504
5
    return Status::OK();
505
5
}
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE6EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE7EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE8EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE9EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE25EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE26EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE11EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE12EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE20EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE28EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE29EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE30EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE35EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE15EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE10EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE23EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE36EEENS_6StatusEPKvPNS_9TExprNodeEii
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE37EEENS_6StatusEPKvPNS_9TExprNodeEii
506
// NOLINTEND(readability-function-size)
507
508
TExprNode create_texpr_node_from(const void* data, const PrimitiveType& type, int precision = 0,
509
                                 int scale = 0);
510
511
#include "common/compile_check_end.h"
512
} // namespace doris