Coverage Report

Created: 2026-08-16 17:43

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
2.39M
    if (_prepared) {                      \
76
119
        return Status::OK();              \
77
119
    }                                     \
78
2.39M
    _prepared = true;                     \
79
2.39M
    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
795
    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
795
        elem.column = elem.column->clone_resized(size);
104
795
        block->insert(std::move(elem));
105
        // just inserted. so no need to check underflow.
106
795
        return block->columns() - 1;
107
795
    }
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.53k
    VExpr() = default;
114
7.01M
    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
    [[maybe_unused]] Status ready_status() const {
140
        if (_prepare_finished && _open_finished) {
141
            return Status::OK();
142
        }
143
        return Status::InternalError(expr_name() + " is not ready when execute");
144
    }
145
146
60.7k
    virtual Status execute(VExprContext* context, Block* block, int* result_column_id) const {
147
60.7k
        ColumnPtr result_column;
148
60.7k
        RETURN_IF_ERROR(execute_column(context, block, nullptr, block->rows(), result_column));
149
60.6k
        *result_column_id = block->columns();
150
60.6k
        block->insert({result_column, execute_type(block), expr_name()});
151
60.6k
        return Status::OK();
152
60.7k
    }
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
5.41M
    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
313
    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
200
    virtual bool can_execute_on_null_map(const DataTypePtr& data_type, int column_id) const {
215
200
        return false;
216
200
    }
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
2.70M
    [[nodiscard]] virtual bool is_blockable() const {
232
2.70M
        return std::any_of(_children.begin(), _children.end(),
233
2.70M
                           [](VExprSPtr child) { return child->is_blockable(); });
234
2.70M
    }
235
236
1.12k
    [[nodiscard]] virtual bool is_deterministic() const {
237
1.12k
        return std::ranges::all_of(
238
1.12k
                _children, [](const VExprSPtr& child) { return child->is_deterministic(); });
239
1.12k
    }
240
241
442
    [[nodiscard]] virtual bool is_safe_to_execute_on_selected_rows() const {
242
442
        return is_deterministic() && std::ranges::all_of(_children, [](const VExprSPtr& child) {
243
249
                   return child->is_safe_to_execute_on_selected_rows();
244
249
               });
245
442
    }
246
247
    // execute current expr with inverted index to filter block. Given a roaring bitmap of match rows
248
1.37k
    virtual Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) {
249
1.37k
        return Status::OK();
250
1.37k
    }
251
252
    virtual ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const;
253
14.2k
    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
102
    virtual bool can_evaluate_dictionary_filter() const { return false; }
261
    virtual ZoneMapFilterResult evaluate_bloom_filter(const BloomFilterEvalContext& ctx) const;
262
92
    virtual bool can_evaluate_bloom_filter() const { return false; }
263
264
    // Get analyzer key for inverted index queries (overridden by VMatchPredicate)
265
0
    [[nodiscard]] virtual const std::string& get_analyzer_key() const {
266
0
        static const std::string empty;
267
0
        return empty;
268
0
    }
269
270
    Status _evaluate_inverted_index(VExprContext* context, const FunctionBasePtr& function,
271
                                    uint32_t segment_num_rows);
272
273
    virtual size_t estimate_memory(const size_t rows);
274
275
    // Only the 4th parameter is used in the runtime filter. In and MinMax need overwrite the
276
    // interface
277
    virtual Status execute_runtime_filter(VExprContext* context, const Block* block,
278
                                          const uint8_t* __restrict filter, size_t count,
279
1
                                          ColumnPtr& result_column, ColumnPtr* arg_column) const {
280
1
        return execute_column(context, block, nullptr, count, result_column);
281
1
    };
282
283
    /// Subclasses overriding this function should call VExpr::Close().
284
    //
285
    /// If scope if FRAGMENT_LOCAL, both fragment- and thread-local state should be torn
286
    /// down. Otherwise, if scope is THREAD_LOCAL, only thread-local state should be torn
287
    /// down.
288
    virtual void close(VExprContext* context, FunctionContext::FunctionStateScope scope);
289
290
12.7M
    DataTypePtr& data_type() { return _data_type; }
291
292
2.36k
    const DataTypePtr& data_type() const { return _data_type; }
293
294
187k
    virtual bool is_slot_ref() const { return _node_type == TExprNodeType::SLOT_REF; }
295
296
95.4k
    virtual bool is_virtual_slot_ref() const {
297
95.4k
        return _node_type == TExprNodeType::VIRTUAL_SLOT_REF;
298
95.4k
    }
299
300
1.04k
    virtual bool is_column_ref() const { return _node_type == TExprNodeType::COLUMN_REF; }
301
302
513k
    virtual bool is_literal() const { return false; }
303
304
3.36M
    virtual TExprNodeType::type node_type() const { return _node_type; }
305
306
54.1k
    TExprOpcode::type op() const { return _opcode; }
307
308
1.25M
    void add_child(const VExprSPtr& expr) { _children.push_back(expr); }
309
47.3k
    VExprSPtr get_child(uint16_t i) const { return _children[i]; }
310
    // Expr's children number is restricted by org.apache.doris.common.Config#expr_children_limit, 10000 default. and strongly not recommend to change.
311
    // There's little to worry about it. uint16 is enough.
312
342k
    uint16_t get_num_children() const { return static_cast<uint16_t>(_children.size()); }
313
314
4.11M
    virtual bool is_rf_wrapper() const {
315
4.11M
        return std::ranges::any_of(_children.begin(), _children.end(),
316
4.11M
                                   [](VExprSPtr child) { return child->is_rf_wrapper(); });
317
4.11M
    }
318
2.50k
    virtual bool is_topn_filter() const { return false; }
319
320
    static Status create_expr_tree(const TExpr& texpr, VExprContextSPtr& ctx);
321
322
    static Status create_expr_trees(const std::vector<TExpr>& texprs, VExprContextSPtrs& ctxs);
323
324
    static Status prepare(const VExprContextSPtrs& ctxs, RuntimeState* state,
325
                          const RowDescriptor& row_desc);
326
327
    static Status open(const VExprContextSPtrs& ctxs, RuntimeState* state);
328
329
    static Status clone_if_not_exists(const VExprContextSPtrs& ctxs, RuntimeState* state,
330
                                      VExprContextSPtrs& new_ctxs);
331
332
    static bool contains_blockable_function(const VExprContextSPtrs& ctxs);
333
334
    Status deep_clone(VExprSPtr* cloned_expr,
335
                      const VExprCloneNodeOverride& clone_node_override = {}) const;
336
    virtual Status clone_node(VExprSPtr* cloned_expr) const;
337
338
140k
    bool is_nullable() const { return _data_type->is_nullable(); }
339
340
0
    PrimitiveType result_type() const { return _data_type->get_primitive_type(); }
341
342
    static Status create_expr(const TExprNode& expr_node, VExprSPtr& expr);
343
344
    static Status create_tree_from_thrift(const std::vector<TExprNode>& nodes, int* node_idx,
345
                                          VExprSPtr& root_expr, VExprContextSPtr& ctx);
346
347
    static Status check_expr_output_type(const VExprContextSPtrs& ctxs,
348
                                         const RowDescriptor& output_row_desc);
349
2.01M
    virtual const VExprSPtrs& children() const { return _children; }
350
0
    void set_children(const VExprSPtrs& children) { _children = children; }
351
768
    void set_children(VExprSPtrs&& children) { _children = std::move(children); }
352
    void reset_prepare_state();
353
    virtual std::string debug_string() const;
354
    static std::string debug_string(const VExprSPtrs& exprs);
355
    static std::string debug_string(const VExprContextSPtrs& ctxs);
356
357
    static ColumnPtr filter_column_with_selector(const ColumnPtr& origin_column,
358
2.16M
                                                 const Selector* selector, size_t count) {
359
2.16M
        if (selector == nullptr) {
360
2.15M
            DCHECK_EQ(origin_column->size(), count) << origin_column->get_name();
361
2.15M
            return origin_column;
362
2.15M
        }
363
2.16M
        DCHECK_EQ(count, selector->size());
364
9.38k
        auto mutable_column = origin_column->clone_empty();
365
9.38k
        origin_column->append_data_by_selector(mutable_column, *selector);
366
9.38k
        DCHECK_EQ(mutable_column->size(), count);
367
9.38k
        return mutable_column;
368
2.16M
    }
369
370
0
    bool is_and_expr() const { return _fn.name.function_name == "and"; }
371
2.67k
    bool is_like_expr() const { return _fn.name.function_name == "like"; }
372
373
1.04M
    const TFunction& fn() const { return _fn; }
374
375
    /// Returns true if expr doesn't contain slotrefs, i.e., can be evaluated
376
    /// with get_value(NULL). The default implementation returns true if all of
377
    /// the children are constant.
378
    virtual bool is_constant() const;
379
380
    /// If this expr is constant, evaluates the expr with no input row argument and returns
381
    /// the output. Returns nullptr if the argument is not constant. The returned ColumnPtr is
382
    /// owned by this expr. This should only be called after Open() has been called on this
383
    /// expr.
384
    MOCK_FUNCTION Status get_const_col(VExprContext* context,
385
                                       std::shared_ptr<ColumnPtrWrapper>* column_wrapper);
386
387
1.57k
    int fn_context_index() const { return _fn_context_index; }
388
389
1.54M
    static VExprSPtr expr_without_cast(const VExprSPtr& expr) {
390
1.54M
        if (expr->node_type() == TExprNodeType::CAST_EXPR) {
391
14.2k
            return expr_without_cast(expr->_children[0]);
392
14.2k
        }
393
1.52M
        return expr;
394
1.54M
    }
395
396
2.76k
    virtual double execute_cost() const {
397
2.76k
        double cost = 1.0;
398
4.89k
        for (const auto& child : _children) {
399
4.89k
            cost += child->execute_cost();
400
4.89k
        }
401
2.76k
        return cost;
402
2.76k
    }
403
404
    // If this expr is a RuntimeFilterWrapper, this method will return an underlying rf expression
405
169
    virtual VExprSPtr get_impl() const { return {}; }
406
407
    // If this expr is a BloomPredicate, this method will return a BloomFilterFunc
408
0
    virtual std::shared_ptr<BloomFilterFuncBase> get_bloom_filter_func() const {
409
0
        throw Exception(Status::FatalError(
410
0
                "Method 'get_bloom_filter_func()' is not supported in expression: {}",
411
0
                this->debug_string()));
412
0
    }
413
414
1.71k
    virtual std::shared_ptr<HybridSetBase> get_set_func() const { return nullptr; }
415
416
    // fast_execute can direct copy expr filter result which build by apply index in segment_iterator
417
    bool fast_execute(VExprContext* context, const Selector* selector, size_t count,
418
                      ColumnPtr& result_column) const;
419
420
161
    virtual bool can_push_down_to_index() const { return false; }
421
    virtual bool equals(const VExpr& other);
422
0
    void set_index_unique_id(uint32_t index_unique_id) { _index_unique_id = index_unique_id; }
423
0
    uint32_t index_unique_id() const { return _index_unique_id; }
424
425
36.9k
    virtual void collect_slot_column_ids(std::set<int>& column_ids) const {
426
40.4k
        for (auto child : _children) {
427
40.4k
            child->collect_slot_column_ids(column_ids);
428
40.4k
        }
429
36.9k
    }
430
431
#ifdef BE_TEST
432
    void set_node_type(TExprNodeType::type node_type) { _node_type = node_type; }
433
#endif
434
    virtual Status evaluate_ann_range_search(
435
            const segment_v2::AnnRangeSearchRuntime& runtime,
436
            const std::vector<std::unique_ptr<segment_v2::IndexIterator>>& cid_to_index_iterators,
437
            const std::vector<ColumnId>& idx_to_cid,
438
            const std::vector<std::unique_ptr<segment_v2::ColumnIterator>>& column_iterators,
439
            size_t rows_of_segment, roaring::Roaring& row_bitmap,
440
            segment_v2::AnnIndexStats& ann_index_stats, bool enable_result_cache,
441
            AnnRangeSearchEvaluationResult& result);
442
443
    // Prepare the runtime for ANN range search.
444
    // AnnRangeSearchRuntime is used to store the runtime information of ann range search.
445
    // suitable_for_ann_index is used to indicate whether the current expr can be used for ANN range search.
446
    // If suitable_for_ann_index is false, the we will do exhausted search.
447
    virtual void prepare_ann_range_search(const doris::VectorSearchUserParams& params,
448
                                          segment_v2::AnnRangeSearchRuntime& range_search_runtime,
449
                                          bool& suitable_for_ann_index);
450
451
    virtual uint64_t get_digest(uint64_t seed) const;
452
453
protected:
454
    TExprNode clone_texpr_node() const;
455
456
    /// Simple debug string that provides no expr subclass-specific information
457
0
    std::string debug_string(const std::string& expr_name) const {
458
0
        std::stringstream out;
459
0
        out << expr_name << "(" << VExpr::debug_string() << ")";
460
0
        return out.str();
461
0
    }
462
463
    // used in expr name
464
496k
    std::string get_child_names() {
465
496k
        std::string res;
466
954k
        for (auto child : _children) {
467
954k
            if (!res.empty()) {
468
415k
                res += ", ";
469
415k
            }
470
954k
            res += child->expr_name();
471
954k
        }
472
496k
        return res;
473
496k
    }
474
475
    // only for errmsg now
476
2
    std::string get_child_type_names() {
477
2
        std::string res;
478
2
        for (auto child : _children) {
479
2
            if (!res.empty()) {
480
0
                res += ", ";
481
0
            }
482
2
            res += child->expr_name() + ": " + child->data_type()->get_name();
483
2
        }
484
2
        return res;
485
2
    }
486
487
659k
    bool is_const_and_have_executed() const {
488
659k
        return (is_constant() && (_constant_col != nullptr));
489
659k
    }
490
491
    ColumnPtr get_result_from_const(size_t count) const;
492
493
    Status check_constant(const Block& block, ColumnNumbers arguments) const;
494
495
    /// Helper function that calls ctx->register(), sets fn_context_index_, and returns the
496
    /// registered FunctionContext
497
    void register_function_context(RuntimeState* state, VExprContext* context);
498
499
    /// Helper function to initialize function context, called in `open` phase of VExpr:
500
    /// 1. Set constant columns result of function arguments.
501
    /// 2. Call function's prepare() to initialize function state, fragment-local or
502
    /// thread-local according the input `FunctionStateScope` argument.
503
    Status init_function_context(RuntimeState* state, VExprContext* context,
504
                                 FunctionContext::FunctionStateScope scope,
505
                                 const FunctionBasePtr& function) const;
506
507
    /// Helper function to close function context, fragment-local or thread-local according
508
    /// the input `FunctionStateScope` argument. Called in `close` phase of VExpr.
509
    void close_function_context(VExprContext* context, FunctionContext::FunctionStateScope scope,
510
                                const FunctionBasePtr& function) const;
511
512
    TExprNodeType::type _node_type;
513
    // Used to check what opcode
514
    TExprOpcode::type _opcode;
515
    DataTypePtr _data_type;
516
    VExprSPtrs _children; // in few hundreds
517
    TFunction _fn;
518
519
    /// Index to pass to ExprContext::fn_context() to retrieve this expr's FunctionContext.
520
    /// Set in RegisterFunctionContext(). -1 if this expr does not need a FunctionContext and
521
    /// doesn't call RegisterFunctionContext().
522
    int _fn_context_index = -1;
523
524
    // If this expr is constant, this will store and cache the value generated by
525
    // get_const_col()
526
    std::shared_ptr<ColumnPtrWrapper> _constant_col;
527
    bool _prepared = false; // for base class VExpr
528
    // for concrete classes
529
    bool _prepare_finished = false;
530
    bool _open_finished = false;
531
532
    // ensuring uniqueness during index traversal
533
    uint32_t _index_unique_id = 0;
534
    bool _enable_inverted_index_query = true;
535
};
536
537
// NOLINTBEGIN(readability-function-size)
538
template <PrimitiveType T>
539
Status create_texpr_literal_node(const void* data, TExprNode* node, int precision = 0,
540
554k
                                 int scale = 0) {
541
554k
    if constexpr (T == TYPE_BOOLEAN) {
542
23
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
23
        TBoolLiteral boolLiteral;
544
23
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
23
        boolLiteral.__set_value(*origin_value);
546
23
        (*node).__set_bool_literal(boolLiteral);
547
23
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
894
    } else if constexpr (T == TYPE_TINYINT) {
549
894
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
894
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
894
        TIntLiteral intLiteral;
552
894
        intLiteral.__set_value(*origin_value);
553
894
        (*node).__set_int_literal(intLiteral);
554
894
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
904
    } else if constexpr (T == TYPE_SMALLINT) {
556
904
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
904
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
904
        TIntLiteral intLiteral;
559
904
        intLiteral.__set_value(*origin_value);
560
904
        (*node).__set_int_literal(intLiteral);
561
904
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
546k
    } else if constexpr (T == TYPE_INT) {
563
546k
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
546k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
546k
        TIntLiteral intLiteral;
566
546k
        intLiteral.__set_value(*origin_value);
567
546k
        (*node).__set_int_literal(intLiteral);
568
546k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
546k
    } else if constexpr (T == TYPE_BIGINT) {
570
2.74k
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
2.74k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
2.74k
        TIntLiteral intLiteral;
573
2.74k
        intLiteral.__set_value(*origin_value);
574
2.74k
        (*node).__set_int_literal(intLiteral);
575
2.74k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
2.74k
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
88
        auto origin_value = unaligned_load<int128_t>(data);
579
88
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
88
        TLargeIntLiteral large_int_literal;
581
88
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
88
        (*node).__set_large_int_literal(large_int_literal);
583
88
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
88
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
87
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
87
        TDateLiteral date_literal;
587
87
        char convert_buffer[30];
588
87
        origin_value->to_string(convert_buffer);
589
87
        date_literal.__set_value(convert_buffer);
590
87
        (*node).__set_date_literal(date_literal);
591
87
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
87
        if (origin_value->type() == TimeType::TIME_DATE) {
593
43
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
45
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
45
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
45
        }
597
315
    } else if constexpr (T == TYPE_DATEV2) {
598
315
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
315
        TDateLiteral date_literal;
600
315
        char convert_buffer[30];
601
315
        origin_value->to_string(convert_buffer);
602
315
        date_literal.__set_value(convert_buffer);
603
315
        (*node).__set_date_literal(date_literal);
604
315
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
315
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
711
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
711
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
711
        TDateLiteral date_literal;
609
711
        char convert_buffer[30];
610
711
        origin_value->to_string(convert_buffer, scale);
611
711
        date_literal.__set_value(convert_buffer);
612
711
        (*node).__set_date_literal(date_literal);
613
711
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
711
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
711
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
26
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
26
        TDateLiteral date_literal;
618
26
        char convert_buffer[30];
619
26
        origin_value->to_string(convert_buffer);
620
26
        date_literal.__set_value(convert_buffer);
621
26
        (*node).__set_date_literal(date_literal);
622
26
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
26
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
79
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
79
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
79
        TDateLiteral date_literal;
627
79
        auto tz = cctz::utc_time_zone();
628
79
        auto tz_str = origin_value->to_string(tz, scale);
629
79
        date_literal.__set_value(tz_str);
630
79
        (*node).__set_date_literal(date_literal);
631
79
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
79
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
79
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
56
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
56
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
56
        TDecimalLiteral decimal_literal;
639
56
        decimal_literal.__set_value(origin_value.to_string());
640
56
        (*node).__set_decimal_literal(decimal_literal);
641
56
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
56
    } else if constexpr (T == TYPE_DECIMAL32) {
643
44
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
44
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
44
        TDecimalLiteral decimal_literal;
646
44
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
44
        (*node).__set_decimal_literal(decimal_literal);
648
44
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
57
    } else if constexpr (T == TYPE_DECIMAL64) {
650
57
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
57
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
57
        TDecimalLiteral decimal_literal;
653
57
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
57
        (*node).__set_decimal_literal(decimal_literal);
655
57
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
142
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
142
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
142
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
142
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
142
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
142
        (*node).__set_decimal_literal(decimal_literal);
670
142
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
166
    } else if constexpr (T == TYPE_DECIMAL256) {
672
166
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
166
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
166
        TDecimalLiteral decimal_literal;
675
166
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
166
        (*node).__set_decimal_literal(decimal_literal);
677
166
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
166
    } else if constexpr (T == TYPE_FLOAT) {
679
11
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
11
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
11
        TFloatLiteral float_literal;
682
11
        float_literal.__set_value(*origin_value);
683
11
        (*node).__set_float_literal(float_literal);
684
11
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
43
    } else if constexpr (T == TYPE_DOUBLE) {
686
43
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
43
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
43
        TFloatLiteral float_literal;
689
43
        float_literal.__set_value(*origin_value);
690
43
        (*node).__set_float_literal(float_literal);
691
43
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
1.52k
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
1.52k
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
1.52k
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
1.52k
        TStringLiteral string_literal;
696
1.52k
        string_literal.__set_value(*origin_value);
697
1.52k
        (*node).__set_string_literal(string_literal);
698
1.52k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
1.52k
    } else if constexpr (T == TYPE_IPV4) {
700
32
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
32
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
32
        TIPv4Literal literal;
703
32
        literal.__set_value(*origin_value);
704
32
        (*node).__set_ipv4_literal(literal);
705
32
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
32
    } else if constexpr (T == TYPE_IPV6) {
707
22
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
22
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
22
        TIPv6Literal literal;
710
22
        literal.__set_value(CastToString::from_ip(*origin_value));
711
22
        (*node).__set_ipv6_literal(literal);
712
22
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
22
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
1
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
1
        TTimeV2Literal timev2_literal;
717
1
        timev2_literal.__set_value(*origin_value);
718
1
        (*node).__set_timev2_literal(timev2_literal);
719
1
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
1
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
2
    } else if constexpr (T == TYPE_VARBINARY) {
722
2
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
2
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
2
        TVarBinaryLiteral varbinary_literal;
725
2
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
2
        (*node).__set_varbinary_literal(varbinary_literal);
727
2
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
554k
    return Status::OK();
732
554k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE2EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
23
                                 int scale = 0) {
541
23
    if constexpr (T == TYPE_BOOLEAN) {
542
23
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
23
        TBoolLiteral boolLiteral;
544
23
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
23
        boolLiteral.__set_value(*origin_value);
546
23
        (*node).__set_bool_literal(boolLiteral);
547
23
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
23
    return Status::OK();
732
23
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE3EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
894
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
894
    } else if constexpr (T == TYPE_TINYINT) {
549
894
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
894
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
894
        TIntLiteral intLiteral;
552
894
        intLiteral.__set_value(*origin_value);
553
894
        (*node).__set_int_literal(intLiteral);
554
894
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
894
    return Status::OK();
732
894
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE4EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
904
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
904
    } else if constexpr (T == TYPE_SMALLINT) {
556
904
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
904
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
904
        TIntLiteral intLiteral;
559
904
        intLiteral.__set_value(*origin_value);
560
904
        (*node).__set_int_literal(intLiteral);
561
904
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
904
    return Status::OK();
732
904
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE5EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
546k
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
546k
    } else if constexpr (T == TYPE_INT) {
563
546k
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
546k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
546k
        TIntLiteral intLiteral;
566
546k
        intLiteral.__set_value(*origin_value);
567
546k
        (*node).__set_int_literal(intLiteral);
568
546k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
546k
    return Status::OK();
732
546k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE6EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
2.74k
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
2.74k
    } else if constexpr (T == TYPE_BIGINT) {
570
2.74k
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
2.74k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
2.74k
        TIntLiteral intLiteral;
573
2.74k
        intLiteral.__set_value(*origin_value);
574
2.74k
        (*node).__set_int_literal(intLiteral);
575
2.74k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
2.74k
    return Status::OK();
732
2.74k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE7EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
88
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
88
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
88
        auto origin_value = unaligned_load<int128_t>(data);
579
88
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
88
        TLargeIntLiteral large_int_literal;
581
88
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
88
        (*node).__set_large_int_literal(large_int_literal);
583
88
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
88
    return Status::OK();
732
88
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE8EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
11
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
11
    } else if constexpr (T == TYPE_FLOAT) {
679
11
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
11
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
11
        TFloatLiteral float_literal;
682
11
        float_literal.__set_value(*origin_value);
683
11
        (*node).__set_float_literal(float_literal);
684
11
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
11
    return Status::OK();
732
11
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE9EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
43
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
43
    } else if constexpr (T == TYPE_DOUBLE) {
686
43
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
43
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
43
        TFloatLiteral float_literal;
689
43
        float_literal.__set_value(*origin_value);
690
43
        (*node).__set_float_literal(float_literal);
691
43
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
43
    return Status::OK();
732
43
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE25EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
315
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
315
    } else if constexpr (T == TYPE_DATEV2) {
598
315
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
315
        TDateLiteral date_literal;
600
315
        char convert_buffer[30];
601
315
        origin_value->to_string(convert_buffer);
602
315
        date_literal.__set_value(convert_buffer);
603
315
        (*node).__set_date_literal(date_literal);
604
315
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
315
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
315
    return Status::OK();
732
315
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE26EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
711
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
711
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
711
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
711
        TDateLiteral date_literal;
609
711
        char convert_buffer[30];
610
711
        origin_value->to_string(convert_buffer, scale);
611
711
        date_literal.__set_value(convert_buffer);
612
711
        (*node).__set_date_literal(date_literal);
613
711
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
711
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
711
    return Status::OK();
732
711
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE43EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
26
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
26
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
26
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
26
        TDateLiteral date_literal;
618
26
        char convert_buffer[30];
619
26
        origin_value->to_string(convert_buffer);
620
26
        date_literal.__set_value(convert_buffer);
621
26
        (*node).__set_date_literal(date_literal);
622
26
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
26
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
26
    return Status::OK();
732
26
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE11EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
43
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
43
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
43
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
43
        TDateLiteral date_literal;
587
43
        char convert_buffer[30];
588
43
        origin_value->to_string(convert_buffer);
589
43
        date_literal.__set_value(convert_buffer);
590
43
        (*node).__set_date_literal(date_literal);
591
43
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
43
        if (origin_value->type() == TimeType::TIME_DATE) {
593
43
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
43
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
0
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
43
    return Status::OK();
732
43
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE12EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
44
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
44
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
44
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
44
        TDateLiteral date_literal;
587
44
        char convert_buffer[30];
588
44
        origin_value->to_string(convert_buffer);
589
44
        date_literal.__set_value(convert_buffer);
590
44
        (*node).__set_date_literal(date_literal);
591
44
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
44
        if (origin_value->type() == TimeType::TIME_DATE) {
593
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
45
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
45
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
45
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
44
    return Status::OK();
732
44
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE20EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
56
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
56
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
56
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
56
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
56
        TDecimalLiteral decimal_literal;
639
56
        decimal_literal.__set_value(origin_value.to_string());
640
56
        (*node).__set_decimal_literal(decimal_literal);
641
56
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
56
    return Status::OK();
732
56
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE28EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
44
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
44
    } else if constexpr (T == TYPE_DECIMAL32) {
643
44
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
44
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
44
        TDecimalLiteral decimal_literal;
646
44
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
44
        (*node).__set_decimal_literal(decimal_literal);
648
44
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
44
    return Status::OK();
732
44
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE29EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
57
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
57
    } else if constexpr (T == TYPE_DECIMAL64) {
650
57
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
57
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
57
        TDecimalLiteral decimal_literal;
653
57
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
57
        (*node).__set_decimal_literal(decimal_literal);
655
57
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
57
    return Status::OK();
732
57
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE30EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
142
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
142
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
142
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
142
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
142
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
142
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
142
        (*node).__set_decimal_literal(decimal_literal);
670
142
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
142
    return Status::OK();
732
142
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE35EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
166
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
166
    } else if constexpr (T == TYPE_DECIMAL256) {
672
166
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
166
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
166
        TDecimalLiteral decimal_literal;
675
166
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
166
        (*node).__set_decimal_literal(decimal_literal);
677
166
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
166
    return Status::OK();
732
166
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE15EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
293
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
293
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
293
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
293
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
293
        TStringLiteral string_literal;
696
293
        string_literal.__set_value(*origin_value);
697
293
        (*node).__set_string_literal(string_literal);
698
293
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
293
    return Status::OK();
732
293
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE10EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
1.06k
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
1.06k
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
1.06k
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
1.06k
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
1.06k
        TStringLiteral string_literal;
696
1.06k
        string_literal.__set_value(*origin_value);
697
1.06k
        (*node).__set_string_literal(string_literal);
698
1.06k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
1.06k
    return Status::OK();
732
1.06k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE23EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
166
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
166
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
166
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
166
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
166
        TStringLiteral string_literal;
696
166
        string_literal.__set_value(*origin_value);
697
166
        (*node).__set_string_literal(string_literal);
698
166
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
166
    return Status::OK();
732
166
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE41EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
2
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
2
    } else if constexpr (T == TYPE_VARBINARY) {
722
2
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
2
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
2
        TVarBinaryLiteral varbinary_literal;
725
2
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
2
        (*node).__set_varbinary_literal(varbinary_literal);
727
2
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
2
    return Status::OK();
732
2
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE36EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
32
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
32
    } else if constexpr (T == TYPE_IPV4) {
700
32
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
32
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
32
        TIPv4Literal literal;
703
32
        literal.__set_value(*origin_value);
704
32
        (*node).__set_ipv4_literal(literal);
705
32
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
32
    return Status::OK();
732
32
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE37EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
22
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
22
    } else if constexpr (T == TYPE_IPV6) {
707
22
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
22
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
22
        TIPv6Literal literal;
710
22
        literal.__set_value(CastToString::from_ip(*origin_value));
711
22
        (*node).__set_ipv6_literal(literal);
712
22
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
22
    return Status::OK();
732
22
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE27EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
1
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
        TDateLiteral date_literal;
627
        auto tz = cctz::utc_time_zone();
628
        auto tz_str = origin_value->to_string(tz, scale);
629
        date_literal.__set_value(tz_str);
630
        (*node).__set_date_literal(date_literal);
631
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
1
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
1
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
1
        TTimeV2Literal timev2_literal;
717
1
        timev2_literal.__set_value(*origin_value);
718
1
        (*node).__set_timev2_literal(timev2_literal);
719
1
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
1
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
1
    return Status::OK();
732
1
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE42EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
540
79
                                 int scale = 0) {
541
    if constexpr (T == TYPE_BOOLEAN) {
542
        const auto* origin_value = reinterpret_cast<const bool*>(data);
543
        TBoolLiteral boolLiteral;
544
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
545
        boolLiteral.__set_value(*origin_value);
546
        (*node).__set_bool_literal(boolLiteral);
547
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
548
    } else if constexpr (T == TYPE_TINYINT) {
549
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
550
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
551
        TIntLiteral intLiteral;
552
        intLiteral.__set_value(*origin_value);
553
        (*node).__set_int_literal(intLiteral);
554
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
555
    } else if constexpr (T == TYPE_SMALLINT) {
556
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
557
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
558
        TIntLiteral intLiteral;
559
        intLiteral.__set_value(*origin_value);
560
        (*node).__set_int_literal(intLiteral);
561
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
562
    } else if constexpr (T == TYPE_INT) {
563
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
564
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
565
        TIntLiteral intLiteral;
566
        intLiteral.__set_value(*origin_value);
567
        (*node).__set_int_literal(intLiteral);
568
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
569
    } else if constexpr (T == TYPE_BIGINT) {
570
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
571
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
572
        TIntLiteral intLiteral;
573
        intLiteral.__set_value(*origin_value);
574
        (*node).__set_int_literal(intLiteral);
575
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
576
    } else if constexpr (T == TYPE_LARGEINT) {
577
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
578
        auto origin_value = unaligned_load<int128_t>(data);
579
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
580
        TLargeIntLiteral large_int_literal;
581
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
582
        (*node).__set_large_int_literal(large_int_literal);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
584
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
585
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
586
        TDateLiteral date_literal;
587
        char convert_buffer[30];
588
        origin_value->to_string(convert_buffer);
589
        date_literal.__set_value(convert_buffer);
590
        (*node).__set_date_literal(date_literal);
591
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
592
        if (origin_value->type() == TimeType::TIME_DATE) {
593
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
594
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
595
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
596
        }
597
    } else if constexpr (T == TYPE_DATEV2) {
598
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
599
        TDateLiteral date_literal;
600
        char convert_buffer[30];
601
        origin_value->to_string(convert_buffer);
602
        date_literal.__set_value(convert_buffer);
603
        (*node).__set_date_literal(date_literal);
604
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
605
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
606
    } else if constexpr (T == TYPE_DATETIMEV2) {
607
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
608
        TDateLiteral date_literal;
609
        char convert_buffer[30];
610
        origin_value->to_string(convert_buffer, scale);
611
        date_literal.__set_value(convert_buffer);
612
        (*node).__set_date_literal(date_literal);
613
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
614
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
615
    } else if constexpr (T == TYPE_TIMESTAMP_NS) {
616
        const auto* origin_value = reinterpret_cast<const TimeStampNsValue*>(data);
617
        TDateLiteral date_literal;
618
        char convert_buffer[30];
619
        origin_value->to_string(convert_buffer);
620
        date_literal.__set_value(convert_buffer);
621
        (*node).__set_date_literal(date_literal);
622
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMP_NS));
624
79
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
625
79
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
626
79
        TDateLiteral date_literal;
627
79
        auto tz = cctz::utc_time_zone();
628
79
        auto tz_str = origin_value->to_string(tz, scale);
629
79
        date_literal.__set_value(tz_str);
630
79
        (*node).__set_date_literal(date_literal);
631
79
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
632
79
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
633
    } else if constexpr (T == TYPE_DECIMALV2) {
634
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
635
        // use unaligned_load to avoid UB.
636
        auto origin_value = unaligned_load<DecimalV2Value>(data);
637
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
638
        TDecimalLiteral decimal_literal;
639
        decimal_literal.__set_value(origin_value.to_string());
640
        (*node).__set_decimal_literal(decimal_literal);
641
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
642
    } else if constexpr (T == TYPE_DECIMAL32) {
643
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
644
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
645
        TDecimalLiteral decimal_literal;
646
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
647
        (*node).__set_decimal_literal(decimal_literal);
648
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
649
    } else if constexpr (T == TYPE_DECIMAL64) {
650
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
651
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
652
        TDecimalLiteral decimal_literal;
653
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
654
        (*node).__set_decimal_literal(decimal_literal);
655
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
656
    } else if constexpr (T == TYPE_DECIMAL128I) {
657
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
658
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
659
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
660
        TDecimalLiteral decimal_literal;
661
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
662
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
663
        // final min value of the MinMax RF if the fragment instance has no data.
664
        // Need to truncate the value to the right precision and scale here, to avoid
665
        // error when casting string back to decimal later.
666
        // TODO: this is a temporary solution, the best solution is to produce the
667
        // right min max value at the producer side.
668
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
669
        (*node).__set_decimal_literal(decimal_literal);
670
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
671
    } else if constexpr (T == TYPE_DECIMAL256) {
672
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
673
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
674
        TDecimalLiteral decimal_literal;
675
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
676
        (*node).__set_decimal_literal(decimal_literal);
677
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
678
    } else if constexpr (T == TYPE_FLOAT) {
679
        const auto* origin_value = reinterpret_cast<const float*>(data);
680
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
681
        TFloatLiteral float_literal;
682
        float_literal.__set_value(*origin_value);
683
        (*node).__set_float_literal(float_literal);
684
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
685
    } else if constexpr (T == TYPE_DOUBLE) {
686
        const auto* origin_value = reinterpret_cast<const double*>(data);
687
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
688
        TFloatLiteral float_literal;
689
        float_literal.__set_value(*origin_value);
690
        (*node).__set_float_literal(float_literal);
691
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
692
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
693
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
694
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
695
        TStringLiteral string_literal;
696
        string_literal.__set_value(*origin_value);
697
        (*node).__set_string_literal(string_literal);
698
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
699
    } else if constexpr (T == TYPE_IPV4) {
700
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
701
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
702
        TIPv4Literal literal;
703
        literal.__set_value(*origin_value);
704
        (*node).__set_ipv4_literal(literal);
705
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
706
    } else if constexpr (T == TYPE_IPV6) {
707
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
708
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
709
        TIPv6Literal literal;
710
        literal.__set_value(CastToString::from_ip(*origin_value));
711
        (*node).__set_ipv6_literal(literal);
712
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
713
    } else if constexpr (T == TYPE_TIMEV2) {
714
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
715
        const auto* origin_value = reinterpret_cast<const double*>(data);
716
        TTimeV2Literal timev2_literal;
717
        timev2_literal.__set_value(*origin_value);
718
        (*node).__set_timev2_literal(timev2_literal);
719
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
720
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
721
    } else if constexpr (T == TYPE_VARBINARY) {
722
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
723
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
724
        TVarBinaryLiteral varbinary_literal;
725
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
726
        (*node).__set_varbinary_literal(varbinary_literal);
727
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
728
    } else {
729
        return Status::InvalidArgument("Invalid argument type!");
730
    }
731
79
    return Status::OK();
732
79
}
733
// NOLINTEND(readability-function-size)
734
735
TExprNode create_texpr_node_from(const void* data, const PrimitiveType& type, int precision = 0,
736
                                 int scale = 0);
737
738
TExprNode create_texpr_node_from(const Field& field, const PrimitiveType& type, int precision,
739
                                 int scale);
740
741
} // namespace doris