Coverage Report

Created: 2025-06-07 21:58

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