Coverage Report

Created: 2026-07-27 15:01

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