Coverage Report

Created: 2026-07-22 06:27

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.35M
    if (_prepared) {                      \
76
23.3k
        return Status::OK();              \
77
23.3k
    }                                     \
78
3.35M
    _prepared = true;                     \
79
3.35M
    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.88k
    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.88k
        elem.column = elem.column->clone_resized(size);
104
4.88k
        block->insert(std::move(elem));
105
        // just inserted. so no need to check underflow.
106
4.88k
        return block->columns() - 1;
107
4.88k
    }
108
109
    VExpr(const TExprNode& node);
110
    VExpr(const VExpr& vexpr);
111
    VExpr(DataTypePtr type, bool is_slotref);
112
    // only used for test
113
39.1k
    VExpr() = default;
114
14.2M
    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
120k
    virtual Status execute(VExprContext* context, Block* block, int* result_column_id) const {
147
120k
        ColumnPtr result_column;
148
120k
        RETURN_IF_ERROR(execute_column(context, block, nullptr, block->rows(), result_column));
149
120k
        *result_column_id = block->columns();
150
120k
        block->insert({result_column, execute_type(block), expr_name()});
151
120k
        return Status::OK();
152
120k
    }
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.48M
    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
1
                                                 int column_id) const {
182
1
        return false;
183
1
    }
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.37M
    [[nodiscard]] virtual bool is_blockable() const {
192
4.37M
        return std::any_of(_children.begin(), _children.end(),
193
4.37M
                           [](VExprSPtr child) { return child->is_blockable(); });
194
4.37M
    }
195
196
463k
    [[nodiscard]] virtual bool is_deterministic() const {
197
463k
        return std::ranges::all_of(
198
463k
                _children, [](const VExprSPtr& child) { return child->is_deterministic(); });
199
463k
    }
200
201
193k
    [[nodiscard]] virtual bool is_safe_to_execute_on_selected_rows() const {
202
193k
        return is_deterministic() && std::ranges::all_of(_children, [](const VExprSPtr& child) {
203
124k
                   return child->is_safe_to_execute_on_selected_rows();
204
124k
               });
205
193k
    }
206
207
    // execute current expr with inverted index to filter block. Given a roaring bitmap of match rows
208
1.56k
    virtual Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) {
209
1.56k
        return Status::OK();
210
1.56k
    }
211
212
    virtual ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const;
213
27.2k
    virtual bool can_evaluate_zonemap_filter() const { return false; }
214
    virtual ZoneMapFilterResult evaluate_dictionary_filter(const DictionaryEvalContext& ctx) const;
215
7.87k
    virtual bool can_evaluate_dictionary_filter() const { return false; }
216
    virtual ZoneMapFilterResult evaluate_bloom_filter(const BloomFilterEvalContext& ctx) const;
217
5.27k
    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
19.7M
    DataTypePtr& data_type() { return _data_type; }
246
247
138k
    const DataTypePtr& data_type() const { return _data_type; }
248
249
993k
    virtual bool is_slot_ref() const { return _node_type == TExprNodeType::SLOT_REF; }
250
251
91.1k
    virtual bool is_virtual_slot_ref() const {
252
91.1k
        return _node_type == TExprNodeType::VIRTUAL_SLOT_REF;
253
91.1k
    }
254
255
997
    virtual bool is_column_ref() const { return _node_type == TExprNodeType::COLUMN_REF; }
256
257
839k
    virtual bool is_literal() const { return false; }
258
259
6.14M
    virtual TExprNodeType::type node_type() const { return _node_type; }
260
261
130k
    TExprOpcode::type op() const { return _opcode; }
262
263
1.90M
    void add_child(const VExprSPtr& expr) { _children.push_back(expr); }
264
75.1k
    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.08M
    uint16_t get_num_children() const { return static_cast<uint16_t>(_children.size()); }
268
269
8.05M
    virtual bool is_rf_wrapper() const {
270
8.05M
        return std::ranges::any_of(_children.begin(), _children.end(),
271
8.05M
                                   [](VExprSPtr child) { return child->is_rf_wrapper(); });
272
8.05M
    }
273
18.4k
    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
    Status deep_clone(VExprSPtr* cloned_expr,
290
                      const VExprCloneNodeOverride& clone_node_override = {}) const;
291
    virtual Status clone_node(VExprSPtr* cloned_expr) const;
292
293
166k
    bool is_nullable() const { return _data_type->is_nullable(); }
294
295
0
    PrimitiveType result_type() const { return _data_type->get_primitive_type(); }
296
297
    static Status create_expr(const TExprNode& expr_node, VExprSPtr& expr);
298
299
    static Status create_tree_from_thrift(const std::vector<TExprNode>& nodes, int* node_idx,
300
                                          VExprSPtr& root_expr, VExprContextSPtr& ctx);
301
302
    static Status check_expr_output_type(const VExprContextSPtrs& ctxs,
303
                                         const RowDescriptor& output_row_desc);
304
4.32M
    virtual const VExprSPtrs& children() const { return _children; }
305
0
    void set_children(const VExprSPtrs& children) { _children = children; }
306
750k
    void set_children(VExprSPtrs&& children) { _children = std::move(children); }
307
    void reset_prepare_state();
308
    virtual std::string debug_string() const;
309
    static std::string debug_string(const VExprSPtrs& exprs);
310
    static std::string debug_string(const VExprContextSPtrs& ctxs);
311
312
    static ColumnPtr filter_column_with_selector(const ColumnPtr& origin_column,
313
3.34M
                                                 const Selector* selector, size_t count) {
314
3.34M
        if (selector == nullptr) {
315
3.32M
            DCHECK_EQ(origin_column->size(), count) << origin_column->get_name();
316
3.32M
            return origin_column;
317
3.32M
        }
318
3.34M
        DCHECK_EQ(count, selector->size());
319
10.7k
        auto mutable_column = origin_column->clone_empty();
320
10.7k
        origin_column->append_data_by_selector(mutable_column, *selector);
321
10.7k
        DCHECK_EQ(mutable_column->size(), count);
322
10.7k
        return mutable_column;
323
3.34M
    }
324
325
0
    bool is_and_expr() const { return _fn.name.function_name == "and"; }
326
1.17k
    bool is_like_expr() const { return _fn.name.function_name == "like"; }
327
328
1.85M
    const TFunction& fn() const { return _fn; }
329
330
    /// Returns true if expr doesn't contain slotrefs, i.e., can be evaluated
331
    /// with get_value(NULL). The default implementation returns true if all of
332
    /// the children are constant.
333
    virtual bool is_constant() const;
334
335
    /// If this expr is constant, evaluates the expr with no input row argument and returns
336
    /// the output. Returns nullptr if the argument is not constant. The returned ColumnPtr is
337
    /// owned by this expr. This should only be called after Open() has been called on this
338
    /// expr.
339
    MOCK_FUNCTION Status get_const_col(VExprContext* context,
340
                                       std::shared_ptr<ColumnPtrWrapper>* column_wrapper);
341
342
2.31k
    int fn_context_index() const { return _fn_context_index; }
343
344
2.71M
    static VExprSPtr expr_without_cast(const VExprSPtr& expr) {
345
2.71M
        if (expr->node_type() == TExprNodeType::CAST_EXPR) {
346
15.9k
            return expr_without_cast(expr->_children[0]);
347
15.9k
        }
348
2.69M
        return expr;
349
2.71M
    }
350
351
7.51k
    virtual double execute_cost() const {
352
7.51k
        double cost = 1.0;
353
10.2k
        for (const auto& child : _children) {
354
10.2k
            cost += child->execute_cost();
355
10.2k
        }
356
7.51k
        return cost;
357
7.51k
    }
358
359
    // If this expr is a RuntimeFilterWrapper, this method will return an underlying rf expression
360
86.8k
    virtual VExprSPtr get_impl() const { return {}; }
361
362
    // If this expr is a BloomPredicate, this method will return a BloomFilterFunc
363
0
    virtual std::shared_ptr<BloomFilterFuncBase> get_bloom_filter_func() const {
364
0
        throw Exception(Status::FatalError(
365
0
                "Method 'get_bloom_filter_func()' is not supported in expression: {}",
366
0
                this->debug_string()));
367
0
    }
368
369
2.39k
    virtual std::shared_ptr<HybridSetBase> get_set_func() const { return nullptr; }
370
371
    // fast_execute can direct copy expr filter result which build by apply index in segment_iterator
372
    bool fast_execute(VExprContext* context, const Selector* selector, size_t count,
373
                      ColumnPtr& result_column) const;
374
375
161
    virtual bool can_push_down_to_index() const { return false; }
376
    virtual bool equals(const VExpr& other);
377
0
    void set_index_unique_id(uint32_t index_unique_id) { _index_unique_id = index_unique_id; }
378
0
    uint32_t index_unique_id() const { return _index_unique_id; }
379
380
163k
    virtual void collect_slot_column_ids(std::set<int>& column_ids) const {
381
170k
        for (auto child : _children) {
382
170k
            child->collect_slot_column_ids(column_ids);
383
170k
        }
384
163k
    }
385
386
#ifdef BE_TEST
387
    void set_node_type(TExprNodeType::type node_type) { _node_type = node_type; }
388
#endif
389
    virtual Status evaluate_ann_range_search(
390
            const segment_v2::AnnRangeSearchRuntime& runtime,
391
            const std::vector<std::unique_ptr<segment_v2::IndexIterator>>& cid_to_index_iterators,
392
            const std::vector<ColumnId>& idx_to_cid,
393
            const std::vector<std::unique_ptr<segment_v2::ColumnIterator>>& column_iterators,
394
            size_t rows_of_segment, roaring::Roaring& row_bitmap,
395
            segment_v2::AnnIndexStats& ann_index_stats, bool enable_result_cache,
396
            AnnRangeSearchEvaluationResult& result);
397
398
    // Prepare the runtime for ANN range search.
399
    // AnnRangeSearchRuntime is used to store the runtime information of ann range search.
400
    // suitable_for_ann_index is used to indicate whether the current expr can be used for ANN range search.
401
    // If suitable_for_ann_index is false, the we will do exhausted search.
402
    virtual void prepare_ann_range_search(const doris::VectorSearchUserParams& params,
403
                                          segment_v2::AnnRangeSearchRuntime& range_search_runtime,
404
                                          bool& suitable_for_ann_index);
405
406
    virtual uint64_t get_digest(uint64_t seed) const;
407
408
protected:
409
    TExprNode clone_texpr_node() const;
410
411
    /// Simple debug string that provides no expr subclass-specific information
412
0
    std::string debug_string(const std::string& expr_name) const {
413
0
        std::stringstream out;
414
0
        out << expr_name << "(" << VExpr::debug_string() << ")";
415
0
        return out.str();
416
0
    }
417
418
    // used in expr name
419
799k
    std::string get_child_names() {
420
799k
        std::string res;
421
1.54M
        for (auto child : _children) {
422
1.54M
            if (!res.empty()) {
423
696k
                res += ", ";
424
696k
            }
425
1.54M
            res += child->expr_name();
426
1.54M
        }
427
799k
        return res;
428
799k
    }
429
430
    // only for errmsg now
431
2
    std::string get_child_type_names() {
432
2
        std::string res;
433
2
        for (auto child : _children) {
434
2
            if (!res.empty()) {
435
0
                res += ", ";
436
0
            }
437
2
            res += child->expr_name() + ": " + child->data_type()->get_name();
438
2
        }
439
2
        return res;
440
2
    }
441
442
1.13M
    bool is_const_and_have_executed() const {
443
1.13M
        return (is_constant() && (_constant_col != nullptr));
444
1.13M
    }
445
446
    ColumnPtr get_result_from_const(size_t count) const;
447
448
    Status check_constant(const Block& block, ColumnNumbers arguments) const;
449
450
    /// Helper function that calls ctx->register(), sets fn_context_index_, and returns the
451
    /// registered FunctionContext
452
    void register_function_context(RuntimeState* state, VExprContext* context);
453
454
    /// Helper function to initialize function context, called in `open` phase of VExpr:
455
    /// 1. Set constant columns result of function arguments.
456
    /// 2. Call function's prepare() to initialize function state, fragment-local or
457
    /// thread-local according the input `FunctionStateScope` argument.
458
    Status init_function_context(RuntimeState* state, VExprContext* context,
459
                                 FunctionContext::FunctionStateScope scope,
460
                                 const FunctionBasePtr& function) const;
461
462
    /// Helper function to close function context, fragment-local or thread-local according
463
    /// the input `FunctionStateScope` argument. Called in `close` phase of VExpr.
464
    void close_function_context(VExprContext* context, FunctionContext::FunctionStateScope scope,
465
                                const FunctionBasePtr& function) const;
466
467
    TExprNodeType::type _node_type;
468
    // Used to check what opcode
469
    TExprOpcode::type _opcode;
470
    DataTypePtr _data_type;
471
    VExprSPtrs _children; // in few hundreds
472
    TFunction _fn;
473
474
    /// Index to pass to ExprContext::fn_context() to retrieve this expr's FunctionContext.
475
    /// Set in RegisterFunctionContext(). -1 if this expr does not need a FunctionContext and
476
    /// doesn't call RegisterFunctionContext().
477
    int _fn_context_index = -1;
478
479
    // If this expr is constant, this will store and cache the value generated by
480
    // get_const_col()
481
    std::shared_ptr<ColumnPtrWrapper> _constant_col;
482
    bool _prepared = false; // for base class VExpr
483
    // for concrete classes
484
    bool _prepare_finished = false;
485
    bool _open_finished = false;
486
487
    // ensuring uniqueness during index traversal
488
    uint32_t _index_unique_id = 0;
489
    bool _enable_inverted_index_query = true;
490
};
491
492
// NOLINTBEGIN(readability-function-size)
493
template <PrimitiveType T>
494
Status create_texpr_literal_node(const void* data, TExprNode* node, int precision = 0,
495
3.40M
                                 int scale = 0) {
496
3.40M
    if constexpr (T == TYPE_BOOLEAN) {
497
119
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
119
        TBoolLiteral boolLiteral;
499
119
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
119
        boolLiteral.__set_value(*origin_value);
501
119
        (*node).__set_bool_literal(boolLiteral);
502
119
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
667
    } else if constexpr (T == TYPE_TINYINT) {
504
667
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
667
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
667
        TIntLiteral intLiteral;
507
667
        intLiteral.__set_value(*origin_value);
508
667
        (*node).__set_int_literal(intLiteral);
509
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
667
    } else if constexpr (T == TYPE_SMALLINT) {
511
356
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
356
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
356
        TIntLiteral intLiteral;
514
356
        intLiteral.__set_value(*origin_value);
515
356
        (*node).__set_int_literal(intLiteral);
516
356
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
3.38M
    } else if constexpr (T == TYPE_INT) {
518
3.38M
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
519
3.38M
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
520
3.38M
        TIntLiteral intLiteral;
521
3.38M
        intLiteral.__set_value(*origin_value);
522
3.38M
        (*node).__set_int_literal(intLiteral);
523
3.38M
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
524
3.38M
    } else if constexpr (T == TYPE_BIGINT) {
525
7.56k
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
526
7.56k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
527
7.56k
        TIntLiteral intLiteral;
528
7.56k
        intLiteral.__set_value(*origin_value);
529
7.56k
        (*node).__set_int_literal(intLiteral);
530
7.56k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
531
7.56k
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
98
        auto origin_value = unaligned_load<int128_t>(data);
534
98
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
98
        TLargeIntLiteral large_int_literal;
536
98
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
98
        (*node).__set_large_int_literal(large_int_literal);
538
98
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
99
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
99
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
99
        TDateLiteral date_literal;
542
99
        char convert_buffer[30];
543
99
        origin_value->to_string(convert_buffer);
544
99
        date_literal.__set_value(convert_buffer);
545
99
        (*node).__set_date_literal(date_literal);
546
99
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
99
        if (origin_value->type() == TimeType::TIME_DATE) {
548
46
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
53
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
53
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
53
        }
552
654
    } else if constexpr (T == TYPE_DATEV2) {
553
654
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
654
        TDateLiteral date_literal;
555
654
        char convert_buffer[30];
556
654
        origin_value->to_string(convert_buffer);
557
654
        date_literal.__set_value(convert_buffer);
558
654
        (*node).__set_date_literal(date_literal);
559
654
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
654
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
883
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
883
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
883
        TDateLiteral date_literal;
564
883
        char convert_buffer[30];
565
883
        origin_value->to_string(convert_buffer, scale);
566
883
        date_literal.__set_value(convert_buffer);
567
883
        (*node).__set_date_literal(date_literal);
568
883
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
883
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
883
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
83
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
83
        TDateLiteral date_literal;
573
83
        auto tz = cctz::utc_time_zone();
574
83
        auto tz_str = origin_value->to_string(tz, scale);
575
83
        date_literal.__set_value(tz_str);
576
83
        (*node).__set_date_literal(date_literal);
577
83
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
83
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
88
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
88
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
88
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
88
        TDecimalLiteral decimal_literal;
585
88
        decimal_literal.__set_value(origin_value.to_string());
586
88
        (*node).__set_decimal_literal(decimal_literal);
587
88
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
88
    } else if constexpr (T == TYPE_DECIMAL32) {
589
26
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
26
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
26
        TDecimalLiteral decimal_literal;
592
26
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
26
        (*node).__set_decimal_literal(decimal_literal);
594
26
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
701
    } else if constexpr (T == TYPE_DECIMAL64) {
596
701
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
701
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
701
        TDecimalLiteral decimal_literal;
599
701
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
701
        (*node).__set_decimal_literal(decimal_literal);
601
701
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
701
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
166
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
166
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
166
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
166
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
166
        (*node).__set_decimal_literal(decimal_literal);
616
166
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
166
    } else if constexpr (T == TYPE_DECIMAL256) {
618
62
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
62
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
62
        TDecimalLiteral decimal_literal;
621
62
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
62
        (*node).__set_decimal_literal(decimal_literal);
623
62
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
163
    } else if constexpr (T == TYPE_FLOAT) {
625
163
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
163
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
163
        TFloatLiteral float_literal;
628
163
        float_literal.__set_value(*origin_value);
629
163
        (*node).__set_float_literal(float_literal);
630
163
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
163
    } else if constexpr (T == TYPE_DOUBLE) {
632
32
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
32
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
32
        TFloatLiteral float_literal;
635
32
        float_literal.__set_value(*origin_value);
636
32
        (*node).__set_float_literal(float_literal);
637
32
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
12.7k
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
12.7k
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
12.7k
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
12.7k
        TStringLiteral string_literal;
642
12.7k
        string_literal.__set_value(*origin_value);
643
12.7k
        (*node).__set_string_literal(string_literal);
644
12.7k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
12.7k
    } else if constexpr (T == TYPE_IPV4) {
646
48
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
48
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
48
        TIPv4Literal literal;
649
48
        literal.__set_value(*origin_value);
650
48
        (*node).__set_ipv4_literal(literal);
651
48
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
48
    } else if constexpr (T == TYPE_IPV6) {
653
26
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
26
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
26
        TIPv6Literal literal;
656
26
        literal.__set_value(CastToString::from_ip(*origin_value));
657
26
        (*node).__set_ipv6_literal(literal);
658
26
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
26
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
1
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
1
        TTimeV2Literal timev2_literal;
664
1
        timev2_literal.__set_value(*origin_value);
665
1
        (*node).__set_timev2_literal(timev2_literal);
666
1
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
1
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
2
    } else if constexpr (T == TYPE_VARBINARY) {
669
2
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
2
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
2
        TVarBinaryLiteral varbinary_literal;
672
2
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
2
        (*node).__set_varbinary_literal(varbinary_literal);
674
2
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
3.40M
    return Status::OK();
679
3.40M
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE2EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
119
                                 int scale = 0) {
496
119
    if constexpr (T == TYPE_BOOLEAN) {
497
119
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
119
        TBoolLiteral boolLiteral;
499
119
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
119
        boolLiteral.__set_value(*origin_value);
501
119
        (*node).__set_bool_literal(boolLiteral);
502
119
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
119
    return Status::OK();
679
119
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE3EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
667
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
667
    } else if constexpr (T == TYPE_TINYINT) {
504
667
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
667
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
667
        TIntLiteral intLiteral;
507
667
        intLiteral.__set_value(*origin_value);
508
667
        (*node).__set_int_literal(intLiteral);
509
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
667
    return Status::OK();
679
667
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE4EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
356
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
356
    } else if constexpr (T == TYPE_SMALLINT) {
511
356
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
356
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
356
        TIntLiteral intLiteral;
514
356
        intLiteral.__set_value(*origin_value);
515
356
        (*node).__set_int_literal(intLiteral);
516
356
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
356
    return Status::OK();
679
356
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE5EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
3.38M
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
3.38M
    } else if constexpr (T == TYPE_INT) {
518
3.38M
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
519
3.38M
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
520
3.38M
        TIntLiteral intLiteral;
521
3.38M
        intLiteral.__set_value(*origin_value);
522
3.38M
        (*node).__set_int_literal(intLiteral);
523
3.38M
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
3.38M
    return Status::OK();
679
3.38M
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE6EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
7.56k
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
7.56k
    } else if constexpr (T == TYPE_BIGINT) {
525
7.56k
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
526
7.56k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
527
7.56k
        TIntLiteral intLiteral;
528
7.56k
        intLiteral.__set_value(*origin_value);
529
7.56k
        (*node).__set_int_literal(intLiteral);
530
7.56k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
7.56k
    return Status::OK();
679
7.56k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE7EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
98
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
98
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
98
        auto origin_value = unaligned_load<int128_t>(data);
534
98
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
98
        TLargeIntLiteral large_int_literal;
536
98
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
98
        (*node).__set_large_int_literal(large_int_literal);
538
98
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
98
    return Status::OK();
679
98
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE8EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
163
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
163
    } else if constexpr (T == TYPE_FLOAT) {
625
163
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
163
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
163
        TFloatLiteral float_literal;
628
163
        float_literal.__set_value(*origin_value);
629
163
        (*node).__set_float_literal(float_literal);
630
163
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
163
    return Status::OK();
679
163
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE9EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
32
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
32
    } else if constexpr (T == TYPE_DOUBLE) {
632
32
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
32
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
32
        TFloatLiteral float_literal;
635
32
        float_literal.__set_value(*origin_value);
636
32
        (*node).__set_float_literal(float_literal);
637
32
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
32
    return Status::OK();
679
32
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE25EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
654
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
654
    } else if constexpr (T == TYPE_DATEV2) {
553
654
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
654
        TDateLiteral date_literal;
555
654
        char convert_buffer[30];
556
654
        origin_value->to_string(convert_buffer);
557
654
        date_literal.__set_value(convert_buffer);
558
654
        (*node).__set_date_literal(date_literal);
559
654
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
654
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
654
    return Status::OK();
679
654
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE26EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
883
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
883
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
883
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
883
        TDateLiteral date_literal;
564
883
        char convert_buffer[30];
565
883
        origin_value->to_string(convert_buffer, scale);
566
883
        date_literal.__set_value(convert_buffer);
567
883
        (*node).__set_date_literal(date_literal);
568
883
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
883
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
883
    return Status::OK();
679
883
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE11EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
46
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
46
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
46
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
46
        TDateLiteral date_literal;
542
46
        char convert_buffer[30];
543
46
        origin_value->to_string(convert_buffer);
544
46
        date_literal.__set_value(convert_buffer);
545
46
        (*node).__set_date_literal(date_literal);
546
46
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
46
        if (origin_value->type() == TimeType::TIME_DATE) {
548
46
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
46
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
0
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
46
    return Status::OK();
679
46
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE12EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
53
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
53
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
53
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
53
        TDateLiteral date_literal;
542
53
        char convert_buffer[30];
543
53
        origin_value->to_string(convert_buffer);
544
53
        date_literal.__set_value(convert_buffer);
545
53
        (*node).__set_date_literal(date_literal);
546
53
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
53
        if (origin_value->type() == TimeType::TIME_DATE) {
548
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
53
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
53
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
53
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
53
    return Status::OK();
679
53
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE20EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
88
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
88
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
88
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
88
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
88
        TDecimalLiteral decimal_literal;
585
88
        decimal_literal.__set_value(origin_value.to_string());
586
88
        (*node).__set_decimal_literal(decimal_literal);
587
88
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
88
    return Status::OK();
679
88
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE28EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
26
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
26
    } else if constexpr (T == TYPE_DECIMAL32) {
589
26
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
26
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
26
        TDecimalLiteral decimal_literal;
592
26
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
26
        (*node).__set_decimal_literal(decimal_literal);
594
26
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
26
    return Status::OK();
679
26
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE29EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
701
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
701
    } else if constexpr (T == TYPE_DECIMAL64) {
596
701
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
701
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
701
        TDecimalLiteral decimal_literal;
599
701
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
701
        (*node).__set_decimal_literal(decimal_literal);
601
701
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
701
    return Status::OK();
679
701
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE30EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
166
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
166
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
166
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
166
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
166
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
166
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
166
        (*node).__set_decimal_literal(decimal_literal);
616
166
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
166
    return Status::OK();
679
166
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE35EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
62
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
62
    } else if constexpr (T == TYPE_DECIMAL256) {
618
62
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
62
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
62
        TDecimalLiteral decimal_literal;
621
62
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
62
        (*node).__set_decimal_literal(decimal_literal);
623
62
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
62
    return Status::OK();
679
62
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE15EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
476
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
476
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
476
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
476
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
476
        TStringLiteral string_literal;
642
476
        string_literal.__set_value(*origin_value);
643
476
        (*node).__set_string_literal(string_literal);
644
476
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
476
    return Status::OK();
679
476
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE10EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
9.94k
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
9.94k
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
9.94k
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
9.94k
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
9.94k
        TStringLiteral string_literal;
642
9.94k
        string_literal.__set_value(*origin_value);
643
9.94k
        (*node).__set_string_literal(string_literal);
644
9.94k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
9.94k
    return Status::OK();
679
9.94k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE23EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
2.37k
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
2.37k
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
2.37k
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
2.37k
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
2.37k
        TStringLiteral string_literal;
642
2.37k
        string_literal.__set_value(*origin_value);
643
2.37k
        (*node).__set_string_literal(string_literal);
644
2.37k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
2.37k
    return Status::OK();
679
2.37k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE41EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
2
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
2
    } else if constexpr (T == TYPE_VARBINARY) {
669
2
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
2
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
2
        TVarBinaryLiteral varbinary_literal;
672
2
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
2
        (*node).__set_varbinary_literal(varbinary_literal);
674
2
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
2
    return Status::OK();
679
2
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE36EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
48
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
48
    } else if constexpr (T == TYPE_IPV4) {
646
48
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
48
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
48
        TIPv4Literal literal;
649
48
        literal.__set_value(*origin_value);
650
48
        (*node).__set_ipv4_literal(literal);
651
48
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
48
    return Status::OK();
679
48
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE37EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
26
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
26
    } else if constexpr (T == TYPE_IPV6) {
653
26
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
26
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
26
        TIPv6Literal literal;
656
26
        literal.__set_value(CastToString::from_ip(*origin_value));
657
26
        (*node).__set_ipv6_literal(literal);
658
26
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
26
    return Status::OK();
679
26
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE27EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
1
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
        TDateLiteral date_literal;
573
        auto tz = cctz::utc_time_zone();
574
        auto tz_str = origin_value->to_string(tz, scale);
575
        date_literal.__set_value(tz_str);
576
        (*node).__set_date_literal(date_literal);
577
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
1
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
1
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
1
        TTimeV2Literal timev2_literal;
664
1
        timev2_literal.__set_value(*origin_value);
665
1
        (*node).__set_timev2_literal(timev2_literal);
666
1
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
1
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
1
    return Status::OK();
679
1
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE42EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
495
83
                                 int scale = 0) {
496
    if constexpr (T == TYPE_BOOLEAN) {
497
        const auto* origin_value = reinterpret_cast<const bool*>(data);
498
        TBoolLiteral boolLiteral;
499
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
500
        boolLiteral.__set_value(*origin_value);
501
        (*node).__set_bool_literal(boolLiteral);
502
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
503
    } else if constexpr (T == TYPE_TINYINT) {
504
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
505
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
506
        TIntLiteral intLiteral;
507
        intLiteral.__set_value(*origin_value);
508
        (*node).__set_int_literal(intLiteral);
509
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
510
    } else if constexpr (T == TYPE_SMALLINT) {
511
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
512
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
513
        TIntLiteral intLiteral;
514
        intLiteral.__set_value(*origin_value);
515
        (*node).__set_int_literal(intLiteral);
516
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
517
    } else if constexpr (T == TYPE_INT) {
518
        const auto* origin_value = reinterpret_cast<const int32_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_INT));
524
    } else if constexpr (T == TYPE_BIGINT) {
525
        const auto* origin_value = reinterpret_cast<const int64_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_BIGINT));
531
    } else if constexpr (T == TYPE_LARGEINT) {
532
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
533
        auto origin_value = unaligned_load<int128_t>(data);
534
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
535
        TLargeIntLiteral large_int_literal;
536
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
537
        (*node).__set_large_int_literal(large_int_literal);
538
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
539
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
540
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
541
        TDateLiteral date_literal;
542
        char convert_buffer[30];
543
        origin_value->to_string(convert_buffer);
544
        date_literal.__set_value(convert_buffer);
545
        (*node).__set_date_literal(date_literal);
546
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
547
        if (origin_value->type() == TimeType::TIME_DATE) {
548
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
549
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
550
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
551
        }
552
    } else if constexpr (T == TYPE_DATEV2) {
553
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
554
        TDateLiteral date_literal;
555
        char convert_buffer[30];
556
        origin_value->to_string(convert_buffer);
557
        date_literal.__set_value(convert_buffer);
558
        (*node).__set_date_literal(date_literal);
559
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
560
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
561
    } else if constexpr (T == TYPE_DATETIMEV2) {
562
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
563
        TDateLiteral date_literal;
564
        char convert_buffer[30];
565
        origin_value->to_string(convert_buffer, scale);
566
        date_literal.__set_value(convert_buffer);
567
        (*node).__set_date_literal(date_literal);
568
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
570
83
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
571
83
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
572
83
        TDateLiteral date_literal;
573
83
        auto tz = cctz::utc_time_zone();
574
83
        auto tz_str = origin_value->to_string(tz, scale);
575
83
        date_literal.__set_value(tz_str);
576
83
        (*node).__set_date_literal(date_literal);
577
83
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
578
83
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
579
    } else if constexpr (T == TYPE_DECIMALV2) {
580
        // data may not be 16-byte aligned (DecimalV2Value stores int128_t);
581
        // use unaligned_load to avoid UB.
582
        auto origin_value = unaligned_load<DecimalV2Value>(data);
583
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
584
        TDecimalLiteral decimal_literal;
585
        decimal_literal.__set_value(origin_value.to_string());
586
        (*node).__set_decimal_literal(decimal_literal);
587
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
588
    } else if constexpr (T == TYPE_DECIMAL32) {
589
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
590
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
591
        TDecimalLiteral decimal_literal;
592
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
593
        (*node).__set_decimal_literal(decimal_literal);
594
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
595
    } else if constexpr (T == TYPE_DECIMAL64) {
596
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
597
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
598
        TDecimalLiteral decimal_literal;
599
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
600
        (*node).__set_decimal_literal(decimal_literal);
601
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
602
    } else if constexpr (T == TYPE_DECIMAL128I) {
603
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
604
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
605
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
606
        TDecimalLiteral decimal_literal;
607
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
608
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
609
        // final min value of the MinMax RF if the fragment instance has no data.
610
        // Need to truncate the value to the right precision and scale here, to avoid
611
        // error when casting string back to decimal later.
612
        // TODO: this is a temporary solution, the best solution is to produce the
613
        // right min max value at the producer side.
614
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
615
        (*node).__set_decimal_literal(decimal_literal);
616
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
617
    } else if constexpr (T == TYPE_DECIMAL256) {
618
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
619
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
620
        TDecimalLiteral decimal_literal;
621
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
622
        (*node).__set_decimal_literal(decimal_literal);
623
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
624
    } else if constexpr (T == TYPE_FLOAT) {
625
        const auto* origin_value = reinterpret_cast<const float*>(data);
626
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
627
        TFloatLiteral float_literal;
628
        float_literal.__set_value(*origin_value);
629
        (*node).__set_float_literal(float_literal);
630
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
631
    } else if constexpr (T == TYPE_DOUBLE) {
632
        const auto* origin_value = reinterpret_cast<const double*>(data);
633
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
634
        TFloatLiteral float_literal;
635
        float_literal.__set_value(*origin_value);
636
        (*node).__set_float_literal(float_literal);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
638
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
639
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
640
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
641
        TStringLiteral string_literal;
642
        string_literal.__set_value(*origin_value);
643
        (*node).__set_string_literal(string_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
645
    } else if constexpr (T == TYPE_IPV4) {
646
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
647
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
648
        TIPv4Literal literal;
649
        literal.__set_value(*origin_value);
650
        (*node).__set_ipv4_literal(literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
652
    } else if constexpr (T == TYPE_IPV6) {
653
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
654
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
655
        TIPv6Literal literal;
656
        literal.__set_value(CastToString::from_ip(*origin_value));
657
        (*node).__set_ipv6_literal(literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
659
    } else if constexpr (T == TYPE_TIMEV2) {
660
        // the code use for runtime filter but we dont support timev2 as predicate now
661
        // so this part not used
662
        const auto* origin_value = reinterpret_cast<const double*>(data);
663
        TTimeV2Literal timev2_literal;
664
        timev2_literal.__set_value(*origin_value);
665
        (*node).__set_timev2_literal(timev2_literal);
666
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
667
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
668
    } else if constexpr (T == TYPE_VARBINARY) {
669
        const auto* origin_value = reinterpret_cast<const StringView*>(data);
670
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
671
        TVarBinaryLiteral varbinary_literal;
672
        varbinary_literal.__set_value(std::string(origin_value->data(), origin_value->size()));
673
        (*node).__set_varbinary_literal(varbinary_literal);
674
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
675
    } else {
676
        return Status::InvalidArgument("Invalid argument type!");
677
    }
678
83
    return Status::OK();
679
83
}
680
// NOLINTEND(readability-function-size)
681
682
TExprNode create_texpr_node_from(const void* data, const PrimitiveType& type, int precision = 0,
683
                                 int scale = 0);
684
685
TExprNode create_texpr_node_from(const Field& field, const PrimitiveType& type, int precision,
686
                                 int scale);
687
688
} // namespace doris