Coverage Report

Created: 2026-07-30 13:04

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