Coverage Report

Created: 2026-08-18 22:01

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