Coverage Report

Created: 2026-06-03 17:43

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