Coverage Report

Created: 2026-07-02 14:47

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vexpr.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
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 <functional>
28
#include <memory>
29
#include <ostream>
30
#include <string>
31
#include <utility>
32
#include <vector>
33
34
#include "common/be_mock_util.h"
35
#include "common/status.h"
36
#include "core/block/block.h"
37
#include "core/block/column_with_type_and_name.h"
38
#include "core/column/column.h"
39
#include "core/data_type/data_type.h"
40
#include "core/data_type/data_type_ipv6.h"
41
#include "core/data_type/define_primitive_type.h"
42
#include "core/extended_types.h"
43
#include "core/string_view.h"
44
#include "core/types.h"
45
#include "core/value/large_int_value.h"
46
#include "core/value/timestamptz_value.h"
47
#include "exprs/aggregate/aggregate_function.h"
48
#include "exprs/function/cast/cast_to_string.h"
49
#include "exprs/function/function.h"
50
#include "exprs/function_context.h"
51
#include "exprs/vexpr_fwd.h"
52
#include "storage/index/ann/ann_search_params.h"
53
#include "storage/index/index_reader.h"
54
#include "storage/index/inverted/inverted_index_reader.h"
55
#include "storage/index/zone_map/zonemap_filter_result.h"
56
#include "util/date_func.h"
57
#include "util/unaligned.h"
58
59
namespace doris {
60
class BloomFilterFuncBase;
61
class HybridSetBase;
62
class ObjectPool;
63
class RowDescriptor;
64
class RuntimeState;
65
class ZoneMapEvalContext;
66
67
namespace segment_v2 {
68
class IndexIterator;
69
class ColumnIterator;
70
struct AnnRangeSearchRuntime;
71
}; // namespace segment_v2
72
73
#define RETURN_IF_ERROR_OR_PREPARED(stmt) \
74
1.00k
    if (_prepared) {                      \
75
58
        return Status::OK();              \
76
58
    }                                     \
77
1.00k
    _prepared = true;                     \
78
1.00k
    RETURN_IF_ERROR(stmt);
79
80
// VExpr should be used as shared pointer because it will be passed between classes
81
// like runtime filter to scan node, or from scannode to scanner. We could not make sure
82
// the relatioinship between threads and classes.
83
84
using Selector = IColumn::Selector;
85
using VExprCloneNodeOverride = std::function<Status(const VExpr&, VExprSPtr*)>;
86
87
struct AnnRangeSearchEvaluationResult {
88
    // Indicates whether the expr row_bitmap has been updated.
89
    bool executed = false;
90
    // Indicates whether the virtual column is fulfilled.
91
    // NOTE, if there is no virtual column in the expr tree, and expr
92
    // is evaluated by ann index, this flag is still true.
93
    bool dist_fulfilled = false;
94
};
95
96
class VExpr {
97
public:
98
    // resize inserted param column to make sure column size equal to block.rows() and return param column index
99
    // keep return type same with block::columns()
100
0
    static uint32_t insert_param(Block* block, ColumnWithTypeAndName&& elem, size_t size) {
101
        // usually elem.column always is const column, so we just clone it.
102
0
        elem.column = elem.column->clone_resized(size);
103
0
        block->insert(std::move(elem));
104
        // just inserted. so no need to check underflow.
105
0
        return block->columns() - 1;
106
0
    }
107
108
    VExpr(const TExprNode& node);
109
    VExpr(const VExpr& vexpr);
110
    VExpr(DataTypePtr type, bool is_slotref);
111
    // only used for test
112
2.33k
    VExpr() = default;
113
806k
    virtual ~VExpr() = default;
114
115
    virtual const std::string& expr_name() const = 0;
116
0
    virtual std::string expr_label() { return ""; }
117
118
    /// Initializes this expr instance for execution. This does not include initializing
119
    /// state in the VExprContext; 'context' should only be used to register a
120
    /// FunctionContext via RegisterFunctionContext().
121
    ///
122
    /// Subclasses overriding this function should call VExpr::Prepare() to recursively call
123
    /// Prepare() on the expr tree
124
    /// row_desc used in vslot_ref and some subclass to specify column
125
    virtual Status prepare(RuntimeState* state, const RowDescriptor& row_desc,
126
                           VExprContext* context);
127
128
    /// Initializes 'context' for execution. If scope if FRAGMENT_LOCAL, both fragment- and
129
    /// thread-local state should be initialized. Otherwise, if scope is THREAD_LOCAL, only
130
    /// thread-local state should be initialized.
131
    //
132
    /// Subclasses overriding this function should call VExpr::Open() to recursively call
133
    /// Open() on the expr tree
134
    virtual Status open(RuntimeState* state, VExprContext* context,
135
                        FunctionContext::FunctionStateScope scope);
136
137
    // before execute, check if expr has been parepared+opened.
138
0
    [[maybe_unused]] Status ready_status() const {
139
0
        if (_prepare_finished && _open_finished) {
140
0
            return Status::OK();
141
0
        }
142
0
        return Status::InternalError(expr_name() + " is not ready when execute");
143
0
    }
144
145
100
    virtual Status execute(VExprContext* context, Block* block, int* result_column_id) const {
146
100
        ColumnPtr result_column;
147
100
        RETURN_IF_ERROR(execute_column(context, block, nullptr, block->rows(), result_column));
148
94
        *result_column_id = block->columns();
149
94
        block->insert({result_column, execute_type(block), expr_name()});
150
94
        return Status::OK();
151
100
    }
152
153
    // Execute the current expression and return the result column.
154
    // Note: the block will not be modified during execution.
155
    // We allow columns in the block to have different numbers of rows.
156
    // 'count' indicates the number of rows in the result column returned by this expression.
157
    // In the future this interface will add an additional parameter, Selector, which specifies
158
    // which rows in the block should be evaluated.
159
    // If expr is executing constant expressions, then block should be nullptr.
160
161
    Status execute_column(VExprContext* context, const Block* block, const Selector* selector,
162
                          size_t count, ColumnPtr& result_column) const;
163
164
    virtual Status execute_column_impl(VExprContext* context, const Block* block,
165
                                       const Selector* selector, size_t count,
166
                                       ColumnPtr& result_column) const = 0;
167
168
    // Currently, due to fe planning issues, for slot-ref expressions the type of the returned Column may not match data_type.
169
    // Therefore we need a function like this to return the actual type produced by execution.
170
1.35k
    virtual DataTypePtr execute_type(const Block* block) const { return _data_type; }
171
172
    virtual Status execute_filter(VExprContext* context, const Block* block,
173
                                  uint8_t* __restrict result_filter_data, size_t rows,
174
                                  bool accept_null, bool* can_filter_all) const;
175
176
    // `is_blockable` means this expr will be blocked in `execute` (e.g. AI Function, Remote Function)
177
131k
    [[nodiscard]] virtual bool is_blockable() const {
178
131k
        return std::any_of(_children.begin(), _children.end(),
179
131k
                           [](VExprSPtr child) { return child->is_blockable(); });
180
131k
    }
181
182
    // execute current expr with inverted index to filter block. Given a roaring bitmap of match rows
183
0
    virtual Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) {
184
0
        return Status::OK();
185
0
    }
186
187
    virtual ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const;
188
8
    virtual bool can_evaluate_zonemap_filter() const { return false; }
189
190
    // Get analyzer key for inverted index queries (overridden by VMatchPredicate)
191
0
    [[nodiscard]] virtual const std::string& get_analyzer_key() const {
192
0
        static const std::string empty;
193
0
        return empty;
194
0
    }
195
196
    Status _evaluate_inverted_index(VExprContext* context, const FunctionBasePtr& function,
197
                                    uint32_t segment_num_rows);
198
199
    virtual size_t estimate_memory(const size_t rows);
200
201
    // Only the 4th parameter is used in the runtime filter. In and MinMax need overwrite the
202
    // interface
203
    virtual Status execute_runtime_filter(VExprContext* context, const Block* block,
204
                                          const uint8_t* __restrict filter, size_t count,
205
0
                                          ColumnPtr& result_column, ColumnPtr* arg_column) const {
206
0
        return execute_column(context, block, nullptr, count, result_column);
207
0
    };
208
209
    /// Subclasses overriding this function should call VExpr::Close().
210
    //
211
    /// If scope if FRAGMENT_LOCAL, both fragment- and thread-local state should be torn
212
    /// down. Otherwise, if scope is THREAD_LOCAL, only thread-local state should be torn
213
    /// down.
214
    virtual void close(VExprContext* context, FunctionContext::FunctionStateScope scope);
215
216
1.69M
    DataTypePtr& data_type() { return _data_type; }
217
218
292
    const DataTypePtr& data_type() const { return _data_type; }
219
220
1.67k
    virtual bool is_slot_ref() const { return _node_type == TExprNodeType::SLOT_REF; }
221
222
60
    virtual bool is_virtual_slot_ref() const {
223
60
        return _node_type == TExprNodeType::VIRTUAL_SLOT_REF;
224
60
    }
225
226
0
    virtual bool is_column_ref() const { return _node_type == TExprNodeType::COLUMN_REF; }
227
228
390
    virtual bool is_literal() const { return false; }
229
230
11.7k
    virtual TExprNodeType::type node_type() const { return _node_type; }
231
232
644
    TExprOpcode::type op() const { return _opcode; }
233
234
2.22k
    void add_child(const VExprSPtr& expr) { _children.push_back(expr); }
235
154
    VExprSPtr get_child(uint16_t i) const { return _children[i]; }
236
    // Expr's children number is restricted by org.apache.doris.common.Config#expr_children_limit, 10000 default. and strongly not recommend to change.
237
    // There's little to worry about it. uint16 is enough.
238
2.07k
    uint16_t get_num_children() const { return static_cast<uint16_t>(_children.size()); }
239
240
3.28k
    virtual bool is_rf_wrapper() const {
241
3.28k
        return std::ranges::any_of(_children.begin(), _children.end(),
242
3.28k
                                   [](VExprSPtr child) { return child->is_rf_wrapper(); });
243
3.28k
    }
244
8
    virtual bool is_topn_filter() const { return false; }
245
246
    static Status create_expr_tree(const TExpr& texpr, VExprContextSPtr& ctx);
247
248
    static Status create_expr_trees(const std::vector<TExpr>& texprs, VExprContextSPtrs& ctxs);
249
250
    static Status prepare(const VExprContextSPtrs& ctxs, RuntimeState* state,
251
                          const RowDescriptor& row_desc);
252
253
    static Status open(const VExprContextSPtrs& ctxs, RuntimeState* state);
254
255
    static Status clone_if_not_exists(const VExprContextSPtrs& ctxs, RuntimeState* state,
256
                                      VExprContextSPtrs& new_ctxs);
257
258
    static bool contains_blockable_function(const VExprContextSPtrs& ctxs);
259
260
    Status deep_clone(VExprSPtr* cloned_expr,
261
                      const VExprCloneNodeOverride& clone_node_override = {}) const;
262
    virtual Status clone_node(VExprSPtr* cloned_expr) const;
263
264
136
    bool is_nullable() const { return _data_type->is_nullable(); }
265
266
0
    PrimitiveType result_type() const { return _data_type->get_primitive_type(); }
267
268
    static Status create_expr(const TExprNode& expr_node, VExprSPtr& expr);
269
270
    static Status create_tree_from_thrift(const std::vector<TExprNode>& nodes, int* node_idx,
271
                                          VExprSPtr& root_expr, VExprContextSPtr& ctx);
272
273
    static Status check_expr_output_type(const VExprContextSPtrs& ctxs,
274
                                         const RowDescriptor& output_row_desc);
275
13.0k
    virtual const VExprSPtrs& children() const { return _children; }
276
0
    void set_children(const VExprSPtrs& children) { _children = children; }
277
1.00k
    void set_children(VExprSPtrs&& children) { _children = std::move(children); }
278
    void reset_prepare_state();
279
    virtual std::string debug_string() const;
280
    static std::string debug_string(const VExprSPtrs& exprs);
281
    static std::string debug_string(const VExprContextSPtrs& ctxs);
282
283
    static ColumnPtr filter_column_with_selector(const ColumnPtr& origin_column,
284
828
                                                 const Selector* selector, size_t count) {
285
828
        if (selector == nullptr) {
286
828
            DCHECK_EQ(origin_column->size(), count) << origin_column->get_name();
287
828
            return origin_column;
288
828
        }
289
828
        DCHECK_EQ(count, selector->size());
290
0
        auto mutable_column = origin_column->clone_empty();
291
0
        origin_column->append_data_by_selector(mutable_column, *selector);
292
0
        DCHECK_EQ(mutable_column->size(), count);
293
0
        return mutable_column;
294
828
    }
295
296
0
    bool is_and_expr() const { return _fn.name.function_name == "and"; }
297
0
    bool is_like_expr() const { return _fn.name.function_name == "like"; }
298
299
1.23k
    const TFunction& fn() const { return _fn; }
300
301
    /// Returns true if expr doesn't contain slotrefs, i.e., can be evaluated
302
    /// with get_value(NULL). The default implementation returns true if all of
303
    /// the children are constant.
304
    virtual bool is_constant() const;
305
306
    /// If this expr is constant, evaluates the expr with no input row argument and returns
307
    /// the output. Returns nullptr if the argument is not constant. The returned ColumnPtr is
308
    /// owned by this expr. This should only be called after Open() has been called on this
309
    /// expr.
310
    MOCK_FUNCTION Status get_const_col(VExprContext* context,
311
                                       std::shared_ptr<ColumnPtrWrapper>* column_wrapper);
312
313
52
    int fn_context_index() const { return _fn_context_index; }
314
315
898
    static VExprSPtr expr_without_cast(const VExprSPtr& expr) {
316
898
        if (expr->node_type() == TExprNodeType::CAST_EXPR) {
317
8
            return expr_without_cast(expr->_children[0]);
318
8
        }
319
890
        return expr;
320
898
    }
321
322
0
    virtual double execute_cost() const {
323
0
        double cost = 1.0;
324
0
        for (const auto& child : _children) {
325
0
            cost += child->execute_cost();
326
0
        }
327
0
        return cost;
328
0
    }
329
330
    // If this expr is a RuntimeFilterWrapper, this method will return an underlying rf expression
331
2
    virtual VExprSPtr get_impl() const { return {}; }
332
333
    // If this expr is a BloomPredicate, this method will return a BloomFilterFunc
334
0
    virtual std::shared_ptr<BloomFilterFuncBase> get_bloom_filter_func() const {
335
0
        throw Exception(Status::FatalError(
336
0
                "Method 'get_bloom_filter_func()' is not supported in expression: {}",
337
0
                this->debug_string()));
338
0
    }
339
340
112
    virtual std::shared_ptr<HybridSetBase> get_set_func() const { return nullptr; }
341
342
    // fast_execute can direct copy expr filter result which build by apply index in segment_iterator
343
    bool fast_execute(VExprContext* context, const Selector* selector, size_t count,
344
                      ColumnPtr& result_column) const;
345
346
0
    virtual bool can_push_down_to_index() const { return false; }
347
    virtual bool equals(const VExpr& other);
348
0
    void set_index_unique_id(uint32_t index_unique_id) { _index_unique_id = index_unique_id; }
349
0
    uint32_t index_unique_id() const { return _index_unique_id; }
350
351
122
    virtual void collect_slot_column_ids(std::set<int>& column_ids) const {
352
130
        for (auto child : _children) {
353
130
            child->collect_slot_column_ids(column_ids);
354
130
        }
355
122
    }
356
357
#ifdef BE_TEST
358
442
    void set_node_type(TExprNodeType::type node_type) { _node_type = node_type; }
359
#endif
360
    virtual Status evaluate_ann_range_search(
361
            const segment_v2::AnnRangeSearchRuntime& runtime,
362
            const std::vector<std::unique_ptr<segment_v2::IndexIterator>>& cid_to_index_iterators,
363
            const std::vector<ColumnId>& idx_to_cid,
364
            const std::vector<std::unique_ptr<segment_v2::ColumnIterator>>& column_iterators,
365
            size_t rows_of_segment, roaring::Roaring& row_bitmap,
366
            segment_v2::AnnIndexStats& ann_index_stats, bool enable_result_cache,
367
            AnnRangeSearchEvaluationResult& result);
368
369
    // Prepare the runtime for ANN range search.
370
    // AnnRangeSearchRuntime is used to store the runtime information of ann range search.
371
    // suitable_for_ann_index is used to indicate whether the current expr can be used for ANN range search.
372
    // If suitable_for_ann_index is false, the we will do exhausted search.
373
    virtual void prepare_ann_range_search(const doris::VectorSearchUserParams& params,
374
                                          segment_v2::AnnRangeSearchRuntime& range_search_runtime,
375
                                          bool& suitable_for_ann_index);
376
377
    virtual uint64_t get_digest(uint64_t seed) const;
378
379
protected:
380
    TExprNode clone_texpr_node() const;
381
382
    /// Simple debug string that provides no expr subclass-specific information
383
0
    std::string debug_string(const std::string& expr_name) const {
384
0
        std::stringstream out;
385
0
        out << expr_name << "(" << VExpr::debug_string() << ")";
386
0
        return out.str();
387
0
    }
388
389
    // used in expr name
390
348
    std::string get_child_names() {
391
348
        std::string res;
392
568
        for (auto child : _children) {
393
568
            if (!res.empty()) {
394
238
                res += ", ";
395
238
            }
396
568
            res += child->expr_name();
397
568
        }
398
348
        return res;
399
348
    }
400
401
    // only for errmsg now
402
0
    std::string get_child_type_names() {
403
0
        std::string res;
404
0
        for (auto child : _children) {
405
0
            if (!res.empty()) {
406
0
                res += ", ";
407
0
            }
408
0
            res += child->expr_name() + ": " + child->data_type()->get_name();
409
0
        }
410
0
        return res;
411
0
    }
412
413
210
    bool is_const_and_have_executed() const {
414
210
        return (is_constant() && (_constant_col != nullptr));
415
210
    }
416
417
    ColumnPtr get_result_from_const(size_t count) const;
418
419
    Status check_constant(const Block& block, ColumnNumbers arguments) const;
420
421
    /// Helper function that calls ctx->register(), sets fn_context_index_, and returns the
422
    /// registered FunctionContext
423
    void register_function_context(RuntimeState* state, VExprContext* context);
424
425
    /// Helper function to initialize function context, called in `open` phase of VExpr:
426
    /// 1. Set constant columns result of function arguments.
427
    /// 2. Call function's prepare() to initialize function state, fragment-local or
428
    /// thread-local according the input `FunctionStateScope` argument.
429
    Status init_function_context(RuntimeState* state, VExprContext* context,
430
                                 FunctionContext::FunctionStateScope scope,
431
                                 const FunctionBasePtr& function) const;
432
433
    /// Helper function to close function context, fragment-local or thread-local according
434
    /// the input `FunctionStateScope` argument. Called in `close` phase of VExpr.
435
    void close_function_context(VExprContext* context, FunctionContext::FunctionStateScope scope,
436
                                const FunctionBasePtr& function) const;
437
438
    TExprNodeType::type _node_type;
439
    // Used to check what opcode
440
    TExprOpcode::type _opcode;
441
    DataTypePtr _data_type;
442
    VExprSPtrs _children; // in few hundreds
443
    TFunction _fn;
444
445
    /// Index to pass to ExprContext::fn_context() to retrieve this expr's FunctionContext.
446
    /// Set in RegisterFunctionContext(). -1 if this expr does not need a FunctionContext and
447
    /// doesn't call RegisterFunctionContext().
448
    int _fn_context_index = -1;
449
450
    // If this expr is constant, this will store and cache the value generated by
451
    // get_const_col()
452
    std::shared_ptr<ColumnPtrWrapper> _constant_col;
453
    bool _prepared = false; // for base class VExpr
454
    // for concrete classes
455
    bool _prepare_finished = false;
456
    bool _open_finished = false;
457
458
    // ensuring uniqueness during index traversal
459
    uint32_t _index_unique_id = 0;
460
    bool _enable_inverted_index_query = true;
461
};
462
463
// NOLINTBEGIN(readability-function-size)
464
template <PrimitiveType T>
465
Status create_texpr_literal_node(const void* data, TExprNode* node, int precision = 0,
466
532
                                 int scale = 0) {
467
532
    if constexpr (T == TYPE_BOOLEAN) {
468
14
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
14
        TBoolLiteral boolLiteral;
470
14
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
14
        boolLiteral.__set_value(*origin_value);
472
14
        (*node).__set_bool_literal(boolLiteral);
473
14
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
14
    } else if constexpr (T == TYPE_TINYINT) {
475
12
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
12
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
12
        TIntLiteral intLiteral;
478
12
        intLiteral.__set_value(*origin_value);
479
12
        (*node).__set_int_literal(intLiteral);
480
12
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
14
    } else if constexpr (T == TYPE_SMALLINT) {
482
14
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
14
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
14
        TIntLiteral intLiteral;
485
14
        intLiteral.__set_value(*origin_value);
486
14
        (*node).__set_int_literal(intLiteral);
487
14
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
138
    } else if constexpr (T == TYPE_INT) {
489
138
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
138
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
138
        TIntLiteral intLiteral;
492
138
        intLiteral.__set_value(*origin_value);
493
138
        (*node).__set_int_literal(intLiteral);
494
138
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
138
    } else if constexpr (T == TYPE_BIGINT) {
496
42
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
42
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
42
        TIntLiteral intLiteral;
499
42
        intLiteral.__set_value(*origin_value);
500
42
        (*node).__set_int_literal(intLiteral);
501
42
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
42
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
16
        auto origin_value = unaligned_load<int128_t>(data);
505
16
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
16
        TLargeIntLiteral large_int_literal;
507
16
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
16
        (*node).__set_large_int_literal(large_int_literal);
509
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
28
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
28
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
28
        TDateLiteral date_literal;
513
28
        char convert_buffer[30];
514
28
        origin_value->to_string(convert_buffer);
515
28
        date_literal.__set_value(convert_buffer);
516
28
        (*node).__set_date_literal(date_literal);
517
28
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
28
        if (origin_value->type() == TimeType::TIME_DATE) {
519
14
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
14
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
14
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
14
        }
523
28
    } else if constexpr (T == TYPE_DATEV2) {
524
14
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
14
        TDateLiteral date_literal;
526
14
        char convert_buffer[30];
527
14
        origin_value->to_string(convert_buffer);
528
14
        date_literal.__set_value(convert_buffer);
529
14
        (*node).__set_date_literal(date_literal);
530
14
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
14
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
16
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
16
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
16
        TDateLiteral date_literal;
535
16
        char convert_buffer[30];
536
16
        origin_value->to_string(convert_buffer, scale);
537
16
        date_literal.__set_value(convert_buffer);
538
16
        (*node).__set_date_literal(date_literal);
539
16
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
16
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
16
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
16
        TDateLiteral date_literal;
544
16
        auto tz = cctz::utc_time_zone();
545
16
        auto tz_str = origin_value->to_string(tz, scale);
546
16
        date_literal.__set_value(tz_str);
547
16
        (*node).__set_date_literal(date_literal);
548
16
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
16
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
16
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
16
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
16
        TDecimalLiteral decimal_literal;
556
16
        decimal_literal.__set_value(origin_value.to_string());
557
16
        (*node).__set_decimal_literal(decimal_literal);
558
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
16
    } else if constexpr (T == TYPE_DECIMAL32) {
560
16
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
16
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
16
        TDecimalLiteral decimal_literal;
563
16
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
16
        (*node).__set_decimal_literal(decimal_literal);
565
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
16
    } else if constexpr (T == TYPE_DECIMAL64) {
567
16
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
16
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
16
        TDecimalLiteral decimal_literal;
570
16
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
16
        (*node).__set_decimal_literal(decimal_literal);
572
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
18
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
18
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
18
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
18
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
18
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
18
        (*node).__set_decimal_literal(decimal_literal);
587
18
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
18
    } else if constexpr (T == TYPE_DECIMAL256) {
589
16
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
16
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
16
        TDecimalLiteral decimal_literal;
592
16
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
16
        (*node).__set_decimal_literal(decimal_literal);
594
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
16
    } else if constexpr (T == TYPE_FLOAT) {
596
14
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
14
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
14
        TFloatLiteral float_literal;
599
14
        float_literal.__set_value(*origin_value);
600
14
        (*node).__set_float_literal(float_literal);
601
14
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
14
    } else if constexpr (T == TYPE_DOUBLE) {
603
14
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
14
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
14
        TFloatLiteral float_literal;
606
14
        float_literal.__set_value(*origin_value);
607
14
        (*node).__set_float_literal(float_literal);
608
14
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
82
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
82
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
82
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
82
        TStringLiteral string_literal;
613
82
        string_literal.__set_value(*origin_value);
614
82
        (*node).__set_string_literal(string_literal);
615
82
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
82
    } else if constexpr (T == TYPE_IPV4) {
617
12
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
12
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
12
        TIPv4Literal literal;
620
12
        literal.__set_value(*origin_value);
621
12
        (*node).__set_ipv4_literal(literal);
622
12
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
12
    } else if constexpr (T == TYPE_IPV6) {
624
12
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
12
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
12
        TIPv6Literal literal;
627
12
        literal.__set_value(CastToString::from_ip(*origin_value));
628
12
        (*node).__set_ipv6_literal(literal);
629
12
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
12
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
2
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
2
        TTimeV2Literal timev2_literal;
635
2
        timev2_literal.__set_value(*origin_value);
636
2
        (*node).__set_timev2_literal(timev2_literal);
637
2
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
2
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
4
    } else if constexpr (T == TYPE_VARBINARY) {
640
4
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
4
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
4
        TVarBinaryLiteral varbinary_literal;
643
4
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
4
        (*node).__set_varbinary_literal(varbinary_literal);
645
4
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
532
    return Status::OK();
650
532
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE5EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
138
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
138
    } else if constexpr (T == TYPE_INT) {
489
138
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
138
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
138
        TIntLiteral intLiteral;
492
138
        intLiteral.__set_value(*origin_value);
493
138
        (*node).__set_int_literal(intLiteral);
494
138
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
138
    return Status::OK();
650
138
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE2EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
14
                                 int scale = 0) {
467
14
    if constexpr (T == TYPE_BOOLEAN) {
468
14
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
14
        TBoolLiteral boolLiteral;
470
14
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
14
        boolLiteral.__set_value(*origin_value);
472
14
        (*node).__set_bool_literal(boolLiteral);
473
14
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
14
    return Status::OK();
650
14
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE3EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
12
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
12
    } else if constexpr (T == TYPE_TINYINT) {
475
12
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
12
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
12
        TIntLiteral intLiteral;
478
12
        intLiteral.__set_value(*origin_value);
479
12
        (*node).__set_int_literal(intLiteral);
480
12
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
12
    return Status::OK();
650
12
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE4EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
14
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
14
    } else if constexpr (T == TYPE_SMALLINT) {
482
14
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
14
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
14
        TIntLiteral intLiteral;
485
14
        intLiteral.__set_value(*origin_value);
486
14
        (*node).__set_int_literal(intLiteral);
487
14
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
14
    return Status::OK();
650
14
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE6EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
42
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
42
    } else if constexpr (T == TYPE_BIGINT) {
496
42
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
42
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
42
        TIntLiteral intLiteral;
499
42
        intLiteral.__set_value(*origin_value);
500
42
        (*node).__set_int_literal(intLiteral);
501
42
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
42
    return Status::OK();
650
42
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE7EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
16
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
16
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
16
        auto origin_value = unaligned_load<int128_t>(data);
505
16
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
16
        TLargeIntLiteral large_int_literal;
507
16
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
16
        (*node).__set_large_int_literal(large_int_literal);
509
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
16
    return Status::OK();
650
16
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE8EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
14
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
14
    } else if constexpr (T == TYPE_FLOAT) {
596
14
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
14
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
14
        TFloatLiteral float_literal;
599
14
        float_literal.__set_value(*origin_value);
600
14
        (*node).__set_float_literal(float_literal);
601
14
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
14
    return Status::OK();
650
14
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE9EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
14
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
14
    } else if constexpr (T == TYPE_DOUBLE) {
603
14
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
14
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
14
        TFloatLiteral float_literal;
606
14
        float_literal.__set_value(*origin_value);
607
14
        (*node).__set_float_literal(float_literal);
608
14
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
14
    return Status::OK();
650
14
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE15EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
12
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
12
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
12
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
12
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
12
        TStringLiteral string_literal;
613
12
        string_literal.__set_value(*origin_value);
614
12
        (*node).__set_string_literal(string_literal);
615
12
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
12
    return Status::OK();
650
12
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE10EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
12
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
12
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
12
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
12
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
12
        TStringLiteral string_literal;
613
12
        string_literal.__set_value(*origin_value);
614
12
        (*node).__set_string_literal(string_literal);
615
12
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
12
    return Status::OK();
650
12
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE23EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
58
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
58
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
58
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
58
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
58
        TStringLiteral string_literal;
613
58
        string_literal.__set_value(*origin_value);
614
58
        (*node).__set_string_literal(string_literal);
615
58
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
58
    return Status::OK();
650
58
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE11EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
14
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
14
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
14
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
14
        TDateLiteral date_literal;
513
14
        char convert_buffer[30];
514
14
        origin_value->to_string(convert_buffer);
515
14
        date_literal.__set_value(convert_buffer);
516
14
        (*node).__set_date_literal(date_literal);
517
14
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
14
        if (origin_value->type() == TimeType::TIME_DATE) {
519
14
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
14
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
0
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
14
    return Status::OK();
650
14
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE12EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
14
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
14
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
14
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
14
        TDateLiteral date_literal;
513
14
        char convert_buffer[30];
514
14
        origin_value->to_string(convert_buffer);
515
14
        date_literal.__set_value(convert_buffer);
516
14
        (*node).__set_date_literal(date_literal);
517
14
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
14
        if (origin_value->type() == TimeType::TIME_DATE) {
519
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
14
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
14
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
14
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
14
    return Status::OK();
650
14
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE25EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
14
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
14
    } else if constexpr (T == TYPE_DATEV2) {
524
14
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
14
        TDateLiteral date_literal;
526
14
        char convert_buffer[30];
527
14
        origin_value->to_string(convert_buffer);
528
14
        date_literal.__set_value(convert_buffer);
529
14
        (*node).__set_date_literal(date_literal);
530
14
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
14
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
14
    return Status::OK();
650
14
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE26EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
16
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
16
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
16
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
16
        TDateLiteral date_literal;
535
16
        char convert_buffer[30];
536
16
        origin_value->to_string(convert_buffer, scale);
537
16
        date_literal.__set_value(convert_buffer);
538
16
        (*node).__set_date_literal(date_literal);
539
16
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
16
    return Status::OK();
650
16
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE42EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
16
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
16
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
16
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
16
        TDateLiteral date_literal;
544
16
        auto tz = cctz::utc_time_zone();
545
16
        auto tz_str = origin_value->to_string(tz, scale);
546
16
        date_literal.__set_value(tz_str);
547
16
        (*node).__set_date_literal(date_literal);
548
16
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
16
    return Status::OK();
650
16
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE28EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
16
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
16
    } else if constexpr (T == TYPE_DECIMAL32) {
560
16
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
16
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
16
        TDecimalLiteral decimal_literal;
563
16
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
16
        (*node).__set_decimal_literal(decimal_literal);
565
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
16
    return Status::OK();
650
16
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE29EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
16
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
16
    } else if constexpr (T == TYPE_DECIMAL64) {
567
16
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
16
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
16
        TDecimalLiteral decimal_literal;
570
16
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
16
        (*node).__set_decimal_literal(decimal_literal);
572
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
16
    return Status::OK();
650
16
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE30EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
18
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
18
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
18
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
18
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
18
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
18
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
18
        (*node).__set_decimal_literal(decimal_literal);
587
18
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
18
    return Status::OK();
650
18
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE35EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
16
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
16
    } else if constexpr (T == TYPE_DECIMAL256) {
589
16
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
16
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
16
        TDecimalLiteral decimal_literal;
592
16
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
16
        (*node).__set_decimal_literal(decimal_literal);
594
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
16
    return Status::OK();
650
16
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE20EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
16
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
16
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
16
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
16
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
16
        TDecimalLiteral decimal_literal;
556
16
        decimal_literal.__set_value(origin_value.to_string());
557
16
        (*node).__set_decimal_literal(decimal_literal);
558
16
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
16
    return Status::OK();
650
16
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE36EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
12
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
12
    } else if constexpr (T == TYPE_IPV4) {
617
12
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
12
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
12
        TIPv4Literal literal;
620
12
        literal.__set_value(*origin_value);
621
12
        (*node).__set_ipv4_literal(literal);
622
12
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
12
    return Status::OK();
650
12
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE37EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
12
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
12
    } else if constexpr (T == TYPE_IPV6) {
624
12
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
12
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
12
        TIPv6Literal literal;
627
12
        literal.__set_value(CastToString::from_ip(*origin_value));
628
12
        (*node).__set_ipv6_literal(literal);
629
12
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
12
    return Status::OK();
650
12
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE41EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
4
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
        TTimeV2Literal timev2_literal;
635
        timev2_literal.__set_value(*origin_value);
636
        (*node).__set_timev2_literal(timev2_literal);
637
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
4
    } else if constexpr (T == TYPE_VARBINARY) {
640
4
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
4
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
4
        TVarBinaryLiteral varbinary_literal;
643
4
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
4
        (*node).__set_varbinary_literal(varbinary_literal);
645
4
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
4
    return Status::OK();
650
4
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE27EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
466
2
                                 int scale = 0) {
467
    if constexpr (T == TYPE_BOOLEAN) {
468
        const auto* origin_value = reinterpret_cast<const bool*>(data);
469
        TBoolLiteral boolLiteral;
470
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
471
        boolLiteral.__set_value(*origin_value);
472
        (*node).__set_bool_literal(boolLiteral);
473
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
474
    } else if constexpr (T == TYPE_TINYINT) {
475
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
476
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
477
        TIntLiteral intLiteral;
478
        intLiteral.__set_value(*origin_value);
479
        (*node).__set_int_literal(intLiteral);
480
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
481
    } else if constexpr (T == TYPE_SMALLINT) {
482
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
483
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
484
        TIntLiteral intLiteral;
485
        intLiteral.__set_value(*origin_value);
486
        (*node).__set_int_literal(intLiteral);
487
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
488
    } else if constexpr (T == TYPE_INT) {
489
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
490
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
491
        TIntLiteral intLiteral;
492
        intLiteral.__set_value(*origin_value);
493
        (*node).__set_int_literal(intLiteral);
494
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
495
    } else if constexpr (T == TYPE_BIGINT) {
496
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
497
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
498
        TIntLiteral intLiteral;
499
        intLiteral.__set_value(*origin_value);
500
        (*node).__set_int_literal(intLiteral);
501
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
502
    } else if constexpr (T == TYPE_LARGEINT) {
503
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
504
        auto origin_value = unaligned_load<int128_t>(data);
505
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
506
        TLargeIntLiteral large_int_literal;
507
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
508
        (*node).__set_large_int_literal(large_int_literal);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
510
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
511
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
512
        TDateLiteral date_literal;
513
        char convert_buffer[30];
514
        origin_value->to_string(convert_buffer);
515
        date_literal.__set_value(convert_buffer);
516
        (*node).__set_date_literal(date_literal);
517
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
518
        if (origin_value->type() == TimeType::TIME_DATE) {
519
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
520
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
521
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
522
        }
523
    } else if constexpr (T == TYPE_DATEV2) {
524
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
525
        TDateLiteral date_literal;
526
        char convert_buffer[30];
527
        origin_value->to_string(convert_buffer);
528
        date_literal.__set_value(convert_buffer);
529
        (*node).__set_date_literal(date_literal);
530
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
531
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
532
    } else if constexpr (T == TYPE_DATETIMEV2) {
533
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
534
        TDateLiteral date_literal;
535
        char convert_buffer[30];
536
        origin_value->to_string(convert_buffer, scale);
537
        date_literal.__set_value(convert_buffer);
538
        (*node).__set_date_literal(date_literal);
539
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
540
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
541
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
542
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
543
        TDateLiteral date_literal;
544
        auto tz = cctz::utc_time_zone();
545
        auto tz_str = origin_value->to_string(tz, scale);
546
        date_literal.__set_value(tz_str);
547
        (*node).__set_date_literal(date_literal);
548
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
549
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
550
    } else if constexpr (T == TYPE_DECIMALV2) {
551
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
552
        // use unaligned_load to avoid UB.
553
        auto origin_value = unaligned_load<DecimalV2Value>(data);
554
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
555
        TDecimalLiteral decimal_literal;
556
        decimal_literal.__set_value(origin_value.to_string());
557
        (*node).__set_decimal_literal(decimal_literal);
558
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
559
    } else if constexpr (T == TYPE_DECIMAL32) {
560
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
561
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
562
        TDecimalLiteral decimal_literal;
563
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
564
        (*node).__set_decimal_literal(decimal_literal);
565
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
566
    } else if constexpr (T == TYPE_DECIMAL64) {
567
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
568
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
569
        TDecimalLiteral decimal_literal;
570
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
571
        (*node).__set_decimal_literal(decimal_literal);
572
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
573
    } else if constexpr (T == TYPE_DECIMAL128I) {
574
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
575
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
576
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
577
        TDecimalLiteral decimal_literal;
578
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
579
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
580
        // final min value of the MinMax RF if the fragment instance has no data.
581
        // Need to truncate the value to the right precision and scale here, to avoid
582
        // error when casting string back to decimal later.
583
        // TODO: this is a temporary solution, the best solution is to produce the
584
        // right min max value at the producer side.
585
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL256) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
595
    } else if constexpr (T == TYPE_FLOAT) {
596
        const auto* origin_value = reinterpret_cast<const float*>(data);
597
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
598
        TFloatLiteral float_literal;
599
        float_literal.__set_value(*origin_value);
600
        (*node).__set_float_literal(float_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
602
    } else if constexpr (T == TYPE_DOUBLE) {
603
        const auto* origin_value = reinterpret_cast<const double*>(data);
604
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
605
        TFloatLiteral float_literal;
606
        float_literal.__set_value(*origin_value);
607
        (*node).__set_float_literal(float_literal);
608
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
609
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
610
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
611
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
612
        TStringLiteral string_literal;
613
        string_literal.__set_value(*origin_value);
614
        (*node).__set_string_literal(string_literal);
615
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
616
    } else if constexpr (T == TYPE_IPV4) {
617
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
618
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
619
        TIPv4Literal literal;
620
        literal.__set_value(*origin_value);
621
        (*node).__set_ipv4_literal(literal);
622
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
623
    } else if constexpr (T == TYPE_IPV6) {
624
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
625
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
626
        TIPv6Literal literal;
627
        literal.__set_value(CastToString::from_ip(*origin_value));
628
        (*node).__set_ipv6_literal(literal);
629
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
630
2
    } else if constexpr (T == TYPE_TIMEV2) {
631
        // the code use for runtime filter but we dont support timev2 as predicate now
632
        // so this part not used
633
2
        const auto* origin_value = reinterpret_cast<const double*>(data);
634
2
        TTimeV2Literal timev2_literal;
635
2
        timev2_literal.__set_value(*origin_value);
636
2
        (*node).__set_timev2_literal(timev2_literal);
637
2
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
638
2
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
639
    } else if constexpr (T == TYPE_VARBINARY) {
640
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
641
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
642
        TVarBinaryLiteral varbinary_literal;
643
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
644
        (*node).__set_varbinary_literal(varbinary_literal);
645
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
646
    } else {
647
        return Status::InvalidArgument("Invalid argument type!");
648
    }
649
2
    return Status::OK();
650
2
}
651
// NOLINTEND(readability-function-size)
652
653
TExprNode create_texpr_node_from(const void* data, const PrimitiveType& type, int precision = 0,
654
                                 int scale = 0);
655
656
TExprNode create_texpr_node_from(const Field& field, const PrimitiveType& type, int precision,
657
                                 int scale);
658
659
} // namespace doris