Coverage Report

Created: 2026-06-04 13:51

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