Coverage Report

Created: 2026-08-27 03:34

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