Coverage Report

Created: 2026-07-29 00:04

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