Coverage Report

Created: 2026-10-28 07:26

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