Coverage Report

Created: 2026-07-07 03:26

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