Coverage Report

Created: 2026-10-17 00:15

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