Coverage Report

Created: 2026-08-18 17:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/exprs/vexpr.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <gen_cpp/Exprs_types.h>
21
#include <gen_cpp/Opcodes_types.h>
22
#include <gen_cpp/Types_types.h>
23
#include <glog/logging.h>
24
25
#include <cstddef>
26
#include <cstdint>
27
#include <functional>
28
#include <memory>
29
#include <ostream>
30
#include <string>
31
#include <utility>
32
#include <vector>
33
34
#include "common/be_mock_util.h"
35
#include "common/status.h"
36
#include "core/block/block.h"
37
#include "core/block/column_with_type_and_name.h"
38
#include "core/column/column.h"
39
#include "core/data_type/data_type.h"
40
#include "core/data_type/data_type_ipv6.h"
41
#include "core/data_type/define_primitive_type.h"
42
#include "core/extended_types.h"
43
#include "core/string_view.h"
44
#include "core/types.h"
45
#include "core/value/large_int_value.h"
46
#include "core/value/timestamptz_value.h"
47
#include "exprs/aggregate/aggregate_function.h"
48
#include "exprs/expr_zonemap_filter.h"
49
#include "exprs/function/cast/cast_to_string.h"
50
#include "exprs/function/function.h"
51
#include "exprs/function_context.h"
52
#include "exprs/vexpr_fwd.h"
53
#include "storage/index/ann/ann_search_params.h"
54
#include "storage/index/index_reader.h"
55
#include "storage/index/inverted/inverted_index_reader.h"
56
#include "storage/index/zone_map/zonemap_filter_result.h"
57
#include "util/date_func.h"
58
#include "util/unaligned.h"
59
60
namespace doris {
61
class BloomFilterFuncBase;
62
class HybridSetBase;
63
class ObjectPool;
64
class RowDescriptor;
65
class RuntimeState;
66
class ZoneMapEvalContext;
67
68
namespace segment_v2 {
69
class IndexIterator;
70
class ColumnIterator;
71
struct AnnRangeSearchRuntime;
72
}; // namespace segment_v2
73
74
#define RETURN_IF_ERROR_OR_PREPARED(stmt) \
75
2.39M
    if (_prepared) {                      \
76
122
        return Status::OK();              \
77
122
    }                                     \
78
2.39M
    _prepared = true;                     \
79
2.39M
    RETURN_IF_ERROR(stmt);
80
81
// VExpr should be used as shared pointer because it will be passed between classes
82
// like runtime filter to scan node, or from scannode to scanner. We could not make sure
83
// the relatioinship between threads and classes.
84
85
using Selector = IColumn::Selector;
86
using VExprCloneNodeOverride = std::function<Status(const VExpr&, VExprSPtr*)>;
87
88
struct AnnRangeSearchEvaluationResult {
89
    // Indicates whether the expr row_bitmap has been updated.
90
    bool executed = false;
91
    // Indicates whether the virtual column is fulfilled.
92
    // NOTE, if there is no virtual column in the expr tree, and expr
93
    // is evaluated by ann index, this flag is still true.
94
    bool dist_fulfilled = false;
95
};
96
97
class VExpr {
98
public:
99
    // resize inserted param column to make sure column size equal to block.rows() and return param column index
100
    // keep return type same with block::columns()
101
934
    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
934
        elem.column = elem.column->clone_resized(size);
104
934
        block->insert(std::move(elem));
105
        // just inserted. so no need to check underflow.
106
934
        return block->columns() - 1;
107
934
    }
108
109
    VExpr(const TExprNode& node);
110
    VExpr(const VExpr& vexpr);
111
    VExpr(DataTypePtr type, bool is_slotref);
112
    // only used for test
113
1.75k
    VExpr() = default;
114
6.70M
    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
49.3k
    virtual Status execute(VExprContext* context, Block* block, int* result_column_id) const {
147
49.3k
        ColumnPtr result_column;
148
49.3k
        RETURN_IF_ERROR(execute_column(context, block, nullptr, block->rows(), result_column));
149
49.3k
        *result_column_id = block->columns();
150
49.3k
        block->insert({result_column, execute_type(block), expr_name()});
151
49.3k
        return Status::OK();
152
49.3k
    }
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.69M
    [[nodiscard]] virtual bool is_blockable() const {
232
2.69M
        return std::any_of(_children.begin(), _children.end(),
233
2.69M
                           [](VExprSPtr child) { return child->is_blockable(); });
234
2.69M
    }
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.26k
    virtual Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) {
249
1.26k
        return Status::OK();
250
1.26k
    }
251
252
    virtual ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const;
253
14.2k
    virtual bool can_evaluate_zonemap_filter() const { return false; }
254
    // Dictionary evaluation is an optional conservative pruning capability over non-NULL values.
255
    // kNoMatch proves that no dictionary entry can satisfy the expression, kMayMatch means at least
256
    // one entry may satisfy it (or pruning cannot currently disprove it), and kUnsupported means the
257
    // context lacks a compatible binding. Capability must describe expression shape, not the
258
    // current contents of a late-arriving runtime filter, because readers may cache it.
259
    virtual ZoneMapFilterResult evaluate_dictionary_filter(const DictionaryEvalContext& ctx) const;
260
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.4M
    DataTypePtr& data_type() { return _data_type; }
295
296
6.50k
    const DataTypePtr& data_type() const { return _data_type; }
297
298
246k
    virtual bool is_slot_ref() const { return _node_type == TExprNodeType::SLOT_REF; }
299
300
139k
    virtual bool is_virtual_slot_ref() const {
301
139k
        return _node_type == TExprNodeType::VIRTUAL_SLOT_REF;
302
139k
    }
303
304
997
    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.25M
    virtual TExprNodeType::type node_type() const { return _node_type; }
309
310
55.9k
    TExprOpcode::type op() const { return _opcode; }
311
312
1.24M
    void add_child(const VExprSPtr& expr) { _children.push_back(expr); }
313
47.8k
    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
341k
    uint16_t get_num_children() const { return static_cast<uint16_t>(_children.size()); }
317
318
4.03M
    virtual bool is_rf_wrapper() const {
319
4.03M
        return std::ranges::any_of(_children.begin(), _children.end(),
320
4.03M
                                   [](VExprSPtr child) { return child->is_rf_wrapper(); });
321
4.03M
    }
322
2.48k
    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
122k
    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
1.97M
    virtual const VExprSPtrs& children() const { return _children; }
354
0
    void set_children(const VExprSPtrs& children) { _children = children; }
355
828
    void set_children(VExprSPtrs&& children) { _children = std::move(children); }
356
    void reset_prepare_state();
357
    virtual std::string debug_string() const;
358
    static std::string debug_string(const VExprSPtrs& exprs);
359
    static std::string debug_string(const VExprContextSPtrs& ctxs);
360
361
    static ColumnPtr filter_column_with_selector(const ColumnPtr& origin_column,
362
2.21M
                                                 const Selector* selector, size_t count) {
363
2.21M
        if (selector == nullptr) {
364
2.21M
            DCHECK_EQ(origin_column->size(), count) << origin_column->get_name();
365
2.21M
            return origin_column;
366
2.21M
        }
367
2.21M
        DCHECK_EQ(count, selector->size());
368
2.42k
        auto mutable_column = origin_column->clone_empty();
369
2.42k
        origin_column->append_data_by_selector(mutable_column, *selector);
370
2.42k
        DCHECK_EQ(mutable_column->size(), count);
371
2.42k
        return mutable_column;
372
2.21M
    }
373
374
0
    bool is_and_expr() const { return _fn.name.function_name == "and"; }
375
2.57k
    bool is_like_expr() const { return _fn.name.function_name == "like"; }
376
377
1.03M
    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.64k
    int fn_context_index() const { return _fn_context_index; }
392
393
1.52M
    static VExprSPtr expr_without_cast(const VExprSPtr& expr) {
394
1.52M
        if (expr->node_type() == TExprNodeType::CAST_EXPR) {
395
13.8k
            return expr_without_cast(expr->_children[0]);
396
13.8k
        }
397
1.50M
        return expr;
398
1.52M
    }
399
400
2.26k
    virtual double execute_cost() const {
401
2.26k
        double cost = 1.0;
402
4.38k
        for (const auto& child : _children) {
403
4.38k
            cost += child->execute_cost();
404
4.38k
        }
405
2.26k
        return cost;
406
2.26k
    }
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
1.81k
    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
37.8k
    virtual void collect_slot_column_ids(std::set<int>& column_ids) const {
430
41.6k
        for (auto child : _children) {
431
41.6k
            child->collect_slot_column_ids(column_ids);
432
41.6k
        }
433
37.8k
    }
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
950k
        for (auto child : _children) {
470
950k
            if (!res.empty()) {
471
414k
                res += ", ";
472
414k
            }
473
950k
            res += child->expr_name();
474
950k
        }
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
700k
    bool is_const_and_have_executed() const {
491
700k
        return (is_constant() && (_constant_col != nullptr));
492
700k
    }
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
353k
                                 int scale = 0) {
544
353k
    if constexpr (T == TYPE_BOOLEAN) {
545
13
        const auto* origin_value = reinterpret_cast<const bool*>(data);
546
13
        TBoolLiteral boolLiteral;
547
13
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
548
13
        boolLiteral.__set_value(*origin_value);
549
13
        (*node).__set_bool_literal(boolLiteral);
550
13
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
551
1.09k
    } else if constexpr (T == TYPE_TINYINT) {
552
1.09k
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
553
1.09k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
554
1.09k
        TIntLiteral intLiteral;
555
1.09k
        intLiteral.__set_value(*origin_value);
556
1.09k
        (*node).__set_int_literal(intLiteral);
557
1.09k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
558
1.22k
    } else if constexpr (T == TYPE_SMALLINT) {
559
1.22k
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
560
1.22k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
561
1.22k
        TIntLiteral intLiteral;
562
1.22k
        intLiteral.__set_value(*origin_value);
563
1.22k
        (*node).__set_int_literal(intLiteral);
564
1.22k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
565
344k
    } else if constexpr (T == TYPE_INT) {
566
344k
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
567
344k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
568
344k
        TIntLiteral intLiteral;
569
344k
        intLiteral.__set_value(*origin_value);
570
344k
        (*node).__set_int_literal(intLiteral);
571
344k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
572
344k
    } else if constexpr (T == TYPE_BIGINT) {
573
3.46k
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
574
3.46k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
575
3.46k
        TIntLiteral intLiteral;
576
3.46k
        intLiteral.__set_value(*origin_value);
577
3.46k
        (*node).__set_int_literal(intLiteral);
578
3.46k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
579
3.46k
    } else if constexpr (T == TYPE_LARGEINT) {
580
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
581
55
        auto origin_value = unaligned_load<int128_t>(data);
582
55
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
583
55
        TLargeIntLiteral large_int_literal;
584
55
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
585
55
        (*node).__set_large_int_literal(large_int_literal);
586
55
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
587
80
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
588
80
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
589
80
        TDateLiteral date_literal;
590
80
        char convert_buffer[30];
591
80
        origin_value->to_string(convert_buffer);
592
80
        date_literal.__set_value(convert_buffer);
593
80
        (*node).__set_date_literal(date_literal);
594
80
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
595
80
        if (origin_value->type() == TimeType::TIME_DATE) {
596
37
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
597
43
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
598
43
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
599
43
        }
600
290
    } else if constexpr (T == TYPE_DATEV2) {
601
290
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
602
290
        TDateLiteral date_literal;
603
290
        char convert_buffer[30];
604
290
        origin_value->to_string(convert_buffer);
605
290
        date_literal.__set_value(convert_buffer);
606
290
        (*node).__set_date_literal(date_literal);
607
290
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
608
290
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
609
290
    } else if constexpr (T == TYPE_DATETIMEV2) {
610
229
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
611
229
        TDateLiteral date_literal;
612
229
        char convert_buffer[30];
613
229
        origin_value->to_string(convert_buffer, scale);
614
229
        date_literal.__set_value(convert_buffer);
615
229
        (*node).__set_date_literal(date_literal);
616
229
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
617
229
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
618
229
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
619
85
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
85
        TDateLiteral date_literal;
621
85
        auto tz = cctz::utc_time_zone();
622
85
        auto tz_str = origin_value->to_string(tz, scale);
623
85
        date_literal.__set_value(tz_str);
624
85
        (*node).__set_date_literal(date_literal);
625
85
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
85
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
85
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
8
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
8
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
8
        TDecimalLiteral decimal_literal;
633
8
        decimal_literal.__set_value(origin_value.to_string());
634
8
        (*node).__set_decimal_literal(decimal_literal);
635
8
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
66
    } else if constexpr (T == TYPE_DECIMAL32) {
637
66
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
66
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
66
        TDecimalLiteral decimal_literal;
640
66
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
66
        (*node).__set_decimal_literal(decimal_literal);
642
66
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
270
    } else if constexpr (T == TYPE_DECIMAL64) {
644
270
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
270
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
270
        TDecimalLiteral decimal_literal;
647
270
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
270
        (*node).__set_decimal_literal(decimal_literal);
649
270
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
270
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
158
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
158
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
158
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
158
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
158
        (*node).__set_decimal_literal(decimal_literal);
664
158
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
158
    } else if constexpr (T == TYPE_DECIMAL256) {
666
129
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
129
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
129
        TDecimalLiteral decimal_literal;
669
129
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
129
        (*node).__set_decimal_literal(decimal_literal);
671
129
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
129
    } else if constexpr (T == TYPE_FLOAT) {
673
45
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
45
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
45
        TFloatLiteral float_literal;
676
45
        float_literal.__set_value(*origin_value);
677
45
        (*node).__set_float_literal(float_literal);
678
45
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
73
    } else if constexpr (T == TYPE_DOUBLE) {
680
73
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
73
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
73
        TFloatLiteral float_literal;
683
73
        float_literal.__set_value(*origin_value);
684
73
        (*node).__set_float_literal(float_literal);
685
73
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
1.44k
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
1.44k
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
1.44k
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
1.44k
        TStringLiteral string_literal;
690
1.44k
        string_literal.__set_value(*origin_value);
691
1.44k
        (*node).__set_string_literal(string_literal);
692
1.44k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
1.44k
    } else if constexpr (T == TYPE_IPV4) {
694
32
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
32
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
32
        TIPv4Literal literal;
697
32
        literal.__set_value(*origin_value);
698
32
        (*node).__set_ipv4_literal(literal);
699
32
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
32
    } else if constexpr (T == TYPE_IPV6) {
701
22
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
22
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
22
        TIPv6Literal literal;
704
22
        literal.__set_value(CastToString::from_ip(*origin_value));
705
22
        (*node).__set_ipv6_literal(literal);
706
22
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
22
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
1
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
1
        TTimeV2Literal timev2_literal;
711
1
        timev2_literal.__set_value(*origin_value);
712
1
        (*node).__set_timev2_literal(timev2_literal);
713
1
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
1
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
2
    } else if constexpr (T == TYPE_VARBINARY) {
716
2
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
2
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
2
        TVarBinaryLiteral varbinary_literal;
719
2
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
2
        (*node).__set_varbinary_literal(varbinary_literal);
721
2
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
353k
    return Status::OK();
726
353k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE2EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
13
                                 int scale = 0) {
544
13
    if constexpr (T == TYPE_BOOLEAN) {
545
13
        const auto* origin_value = reinterpret_cast<const bool*>(data);
546
13
        TBoolLiteral boolLiteral;
547
13
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
548
13
        boolLiteral.__set_value(*origin_value);
549
13
        (*node).__set_bool_literal(boolLiteral);
550
13
        (*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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
13
    return Status::OK();
726
13
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE3EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
1.09k
                                 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
1.09k
    } else if constexpr (T == TYPE_TINYINT) {
552
1.09k
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
553
1.09k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
554
1.09k
        TIntLiteral intLiteral;
555
1.09k
        intLiteral.__set_value(*origin_value);
556
1.09k
        (*node).__set_int_literal(intLiteral);
557
1.09k
        (*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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
1.09k
    return Status::OK();
726
1.09k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE4EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
1.22k
                                 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
1.22k
    } else if constexpr (T == TYPE_SMALLINT) {
559
1.22k
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
560
1.22k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
561
1.22k
        TIntLiteral intLiteral;
562
1.22k
        intLiteral.__set_value(*origin_value);
563
1.22k
        (*node).__set_int_literal(intLiteral);
564
1.22k
        (*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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
1.22k
    return Status::OK();
726
1.22k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE5EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
344k
                                 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
344k
    } else if constexpr (T == TYPE_INT) {
566
344k
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
567
344k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
568
344k
        TIntLiteral intLiteral;
569
344k
        intLiteral.__set_value(*origin_value);
570
344k
        (*node).__set_int_literal(intLiteral);
571
344k
        (*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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
344k
    return Status::OK();
726
344k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE6EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
3.46k
                                 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
3.46k
    } else if constexpr (T == TYPE_BIGINT) {
573
3.46k
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
574
3.46k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
575
3.46k
        TIntLiteral intLiteral;
576
3.46k
        intLiteral.__set_value(*origin_value);
577
3.46k
        (*node).__set_int_literal(intLiteral);
578
3.46k
        (*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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
3.46k
    return Status::OK();
726
3.46k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE7EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
55
                                 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
55
    } else if constexpr (T == TYPE_LARGEINT) {
580
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
581
55
        auto origin_value = unaligned_load<int128_t>(data);
582
55
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
583
55
        TLargeIntLiteral large_int_literal;
584
55
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
585
55
        (*node).__set_large_int_literal(large_int_literal);
586
55
        (*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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
55
    return Status::OK();
726
55
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE8EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
45
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
45
    } else if constexpr (T == TYPE_FLOAT) {
673
45
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
45
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
45
        TFloatLiteral float_literal;
676
45
        float_literal.__set_value(*origin_value);
677
45
        (*node).__set_float_literal(float_literal);
678
45
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
45
    return Status::OK();
726
45
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE9EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
73
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
73
    } else if constexpr (T == TYPE_DOUBLE) {
680
73
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
73
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
73
        TFloatLiteral float_literal;
683
73
        float_literal.__set_value(*origin_value);
684
73
        (*node).__set_float_literal(float_literal);
685
73
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
73
    return Status::OK();
726
73
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE25EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
290
                                 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
290
    } else if constexpr (T == TYPE_DATEV2) {
601
290
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
602
290
        TDateLiteral date_literal;
603
290
        char convert_buffer[30];
604
290
        origin_value->to_string(convert_buffer);
605
290
        date_literal.__set_value(convert_buffer);
606
290
        (*node).__set_date_literal(date_literal);
607
290
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
608
290
        (*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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
290
    return Status::OK();
726
290
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE26EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
229
                                 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
229
    } else if constexpr (T == TYPE_DATETIMEV2) {
610
229
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
611
229
        TDateLiteral date_literal;
612
229
        char convert_buffer[30];
613
229
        origin_value->to_string(convert_buffer, scale);
614
229
        date_literal.__set_value(convert_buffer);
615
229
        (*node).__set_date_literal(date_literal);
616
229
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
617
229
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
618
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
229
    return Status::OK();
726
229
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE11EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
37
                                 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
37
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
588
37
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
589
37
        TDateLiteral date_literal;
590
37
        char convert_buffer[30];
591
37
        origin_value->to_string(convert_buffer);
592
37
        date_literal.__set_value(convert_buffer);
593
37
        (*node).__set_date_literal(date_literal);
594
37
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
595
37
        if (origin_value->type() == TimeType::TIME_DATE) {
596
37
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
597
37
        } 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
37
    return Status::OK();
726
37
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE12EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
43
                                 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
43
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
588
43
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
589
43
        TDateLiteral date_literal;
590
43
        char convert_buffer[30];
591
43
        origin_value->to_string(convert_buffer);
592
43
        date_literal.__set_value(convert_buffer);
593
43
        (*node).__set_date_literal(date_literal);
594
43
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
595
43
        if (origin_value->type() == TimeType::TIME_DATE) {
596
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
597
43
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
598
43
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
599
43
        }
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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
43
    return Status::OK();
726
43
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE20EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
8
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
8
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
8
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
8
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
8
        TDecimalLiteral decimal_literal;
633
8
        decimal_literal.__set_value(origin_value.to_string());
634
8
        (*node).__set_decimal_literal(decimal_literal);
635
8
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
8
    return Status::OK();
726
8
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE28EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
66
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
66
    } else if constexpr (T == TYPE_DECIMAL32) {
637
66
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
66
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
66
        TDecimalLiteral decimal_literal;
640
66
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
66
        (*node).__set_decimal_literal(decimal_literal);
642
66
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
66
    return Status::OK();
726
66
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE29EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
270
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
270
    } else if constexpr (T == TYPE_DECIMAL64) {
644
270
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
270
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
270
        TDecimalLiteral decimal_literal;
647
270
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
270
        (*node).__set_decimal_literal(decimal_literal);
649
270
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
270
    return Status::OK();
726
270
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE30EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
158
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
158
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
158
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
158
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
158
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
158
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
158
        (*node).__set_decimal_literal(decimal_literal);
664
158
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
158
    return Status::OK();
726
158
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE35EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
129
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
129
    } else if constexpr (T == TYPE_DECIMAL256) {
666
129
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
129
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
129
        TDecimalLiteral decimal_literal;
669
129
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
129
        (*node).__set_decimal_literal(decimal_literal);
671
129
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
129
    return Status::OK();
726
129
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE15EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
449
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
449
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
449
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
449
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
449
        TStringLiteral string_literal;
690
449
        string_literal.__set_value(*origin_value);
691
449
        (*node).__set_string_literal(string_literal);
692
449
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
449
    return Status::OK();
726
449
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE10EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
846
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
846
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
846
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
846
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
846
        TStringLiteral string_literal;
690
846
        string_literal.__set_value(*origin_value);
691
846
        (*node).__set_string_literal(string_literal);
692
846
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
846
    return Status::OK();
726
846
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE23EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
151
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
151
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
151
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
151
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
151
        TStringLiteral string_literal;
690
151
        string_literal.__set_value(*origin_value);
691
151
        (*node).__set_string_literal(string_literal);
692
151
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
151
    return Status::OK();
726
151
}
_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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
2
    } else if constexpr (T == TYPE_VARBINARY) {
716
2
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
2
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
2
        TVarBinaryLiteral varbinary_literal;
719
2
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
2
        (*node).__set_varbinary_literal(varbinary_literal);
721
2
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
2
    return Status::OK();
726
2
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE36EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
32
                                 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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
32
    } else if constexpr (T == TYPE_IPV4) {
694
32
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
32
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
32
        TIPv4Literal literal;
697
32
        literal.__set_value(*origin_value);
698
32
        (*node).__set_ipv4_literal(literal);
699
32
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
32
    return Status::OK();
726
32
}
_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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
22
    } else if constexpr (T == TYPE_IPV6) {
701
22
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
22
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
22
        TIPv6Literal literal;
704
22
        literal.__set_value(CastToString::from_ip(*origin_value));
705
22
        (*node).__set_ipv6_literal(literal);
706
22
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
22
    return Status::OK();
726
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_TIMESTAMPTZ) {
619
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
        TDateLiteral date_literal;
621
        auto tz = cctz::utc_time_zone();
622
        auto tz_str = origin_value->to_string(tz, scale);
623
        date_literal.__set_value(tz_str);
624
        (*node).__set_date_literal(date_literal);
625
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
1
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
1
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
1
        TTimeV2Literal timev2_literal;
711
1
        timev2_literal.__set_value(*origin_value);
712
1
        (*node).__set_timev2_literal(timev2_literal);
713
1
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
1
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
1
    return Status::OK();
726
1
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE42EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
543
85
                                 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
85
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
619
85
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
620
85
        TDateLiteral date_literal;
621
85
        auto tz = cctz::utc_time_zone();
622
85
        auto tz_str = origin_value->to_string(tz, scale);
623
85
        date_literal.__set_value(tz_str);
624
85
        (*node).__set_date_literal(date_literal);
625
85
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
626
85
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
627
    } else if constexpr (T == TYPE_DECIMALV2) {
628
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
629
        // use unaligned_load to avoid UB.
630
        auto origin_value = unaligned_load<DecimalV2Value>(data);
631
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
632
        TDecimalLiteral decimal_literal;
633
        decimal_literal.__set_value(origin_value.to_string());
634
        (*node).__set_decimal_literal(decimal_literal);
635
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
636
    } else if constexpr (T == TYPE_DECIMAL32) {
637
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
638
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
639
        TDecimalLiteral decimal_literal;
640
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
641
        (*node).__set_decimal_literal(decimal_literal);
642
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
643
    } else if constexpr (T == TYPE_DECIMAL64) {
644
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
645
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
646
        TDecimalLiteral decimal_literal;
647
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
648
        (*node).__set_decimal_literal(decimal_literal);
649
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
650
    } else if constexpr (T == TYPE_DECIMAL128I) {
651
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
652
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
653
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
654
        TDecimalLiteral decimal_literal;
655
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
656
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
657
        // final min value of the MinMax RF if the fragment instance has no data.
658
        // Need to truncate the value to the right precision and scale here, to avoid
659
        // error when casting string back to decimal later.
660
        // TODO: this is a temporary solution, the best solution is to produce the
661
        // right min max value at the producer side.
662
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
663
        (*node).__set_decimal_literal(decimal_literal);
664
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
665
    } else if constexpr (T == TYPE_DECIMAL256) {
666
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
667
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
668
        TDecimalLiteral decimal_literal;
669
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
670
        (*node).__set_decimal_literal(decimal_literal);
671
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
672
    } else if constexpr (T == TYPE_FLOAT) {
673
        const auto* origin_value = reinterpret_cast<const float*>(data);
674
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
675
        TFloatLiteral float_literal;
676
        float_literal.__set_value(*origin_value);
677
        (*node).__set_float_literal(float_literal);
678
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
679
    } else if constexpr (T == TYPE_DOUBLE) {
680
        const auto* origin_value = reinterpret_cast<const double*>(data);
681
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
682
        TFloatLiteral float_literal;
683
        float_literal.__set_value(*origin_value);
684
        (*node).__set_float_literal(float_literal);
685
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
686
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
687
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
688
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
689
        TStringLiteral string_literal;
690
        string_literal.__set_value(*origin_value);
691
        (*node).__set_string_literal(string_literal);
692
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
693
    } else if constexpr (T == TYPE_IPV4) {
694
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
695
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
696
        TIPv4Literal literal;
697
        literal.__set_value(*origin_value);
698
        (*node).__set_ipv4_literal(literal);
699
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
700
    } else if constexpr (T == TYPE_IPV6) {
701
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
702
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
703
        TIPv6Literal literal;
704
        literal.__set_value(CastToString::from_ip(*origin_value));
705
        (*node).__set_ipv6_literal(literal);
706
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
707
    } else if constexpr (T == TYPE_TIMEV2) {
708
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
709
        const auto* origin_value = reinterpret_cast<const double*>(data);
710
        TTimeV2Literal timev2_literal;
711
        timev2_literal.__set_value(*origin_value);
712
        (*node).__set_timev2_literal(timev2_literal);
713
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
715
    } else if constexpr (T == TYPE_VARBINARY) {
716
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
717
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
718
        TVarBinaryLiteral varbinary_literal;
719
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
720
        (*node).__set_varbinary_literal(varbinary_literal);
721
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
722
    } else {
723
        return Status::InvalidArgument("Invalid argument type!");
724
    }
725
85
    return Status::OK();
726
85
}
727
// NOLINTEND(readability-function-size)
728
729
TExprNode create_texpr_node_from(const void* data, const PrimitiveType& type, int precision = 0,
730
                                 int scale = 0);
731
732
TExprNode create_texpr_node_from(const Field& field, const PrimitiveType& type, int precision,
733
                                 int scale);
734
735
} // namespace doris