Coverage Report

Created: 2026-07-08 16:10

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
2.40M
    if (_prepared) {                      \
76
69
        return Status::OK();              \
77
69
    }                                     \
78
2.40M
    _prepared = true;                     \
79
2.40M
    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
832
    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
832
        elem.column = elem.column->clone_resized(size);
104
832
        block->insert(std::move(elem));
105
        // just inserted. so no need to check underflow.
106
832
        return block->columns() - 1;
107
832
    }
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.20k
    VExpr() = default;
114
6.76M
    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
50.5k
    virtual Status execute(VExprContext* context, Block* block, int* result_column_id) const {
147
50.5k
        ColumnPtr result_column;
148
50.5k
        RETURN_IF_ERROR(execute_column(context, block, nullptr, block->rows(), result_column));
149
50.5k
        *result_column_id = block->columns();
150
50.5k
        block->insert({result_column, execute_type(block), expr_name()});
151
50.5k
        return Status::OK();
152
50.5k
    }
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
5.57M
    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
2.69M
    [[nodiscard]] virtual bool is_blockable() const {
179
2.69M
        return std::any_of(_children.begin(), _children.end(),
180
2.69M
                           [](VExprSPtr child) { return child->is_blockable(); });
181
2.69M
    }
182
183
    // execute current expr with inverted index to filter block. Given a roaring bitmap of match rows
184
1.54k
    virtual Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) {
185
1.54k
        return Status::OK();
186
1.54k
    }
187
188
    virtual ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const;
189
13.2k
    virtual bool can_evaluate_zonemap_filter() const { return false; }
190
    virtual ZoneMapFilterResult evaluate_dictionary_filter(const DictionaryEvalContext& ctx) const;
191
30
    virtual bool can_evaluate_dictionary_filter() const { return false; }
192
    virtual ZoneMapFilterResult evaluate_bloom_filter(const BloomFilterEvalContext& ctx) const;
193
43
    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
12.8M
    DataTypePtr& data_type() { return _data_type; }
222
223
2.22k
    const DataTypePtr& data_type() const { return _data_type; }
224
225
183k
    virtual bool is_slot_ref() const { return _node_type == TExprNodeType::SLOT_REF; }
226
227
87.8k
    virtual bool is_virtual_slot_ref() const {
228
87.8k
        return _node_type == TExprNodeType::VIRTUAL_SLOT_REF;
229
87.8k
    }
230
231
281
    virtual bool is_column_ref() const { return _node_type == TExprNodeType::COLUMN_REF; }
232
233
510k
    virtual bool is_literal() const { return false; }
234
235
3.28M
    virtual TExprNodeType::type node_type() const { return _node_type; }
236
237
51.3k
    TExprOpcode::type op() const { return _opcode; }
238
239
1.24M
    void add_child(const VExprSPtr& expr) { _children.push_back(expr); }
240
45.2k
    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
428k
    uint16_t get_num_children() const { return static_cast<uint16_t>(_children.size()); }
244
245
4.03M
    virtual bool is_rf_wrapper() const {
246
4.03M
        return std::ranges::any_of(_children.begin(), _children.end(),
247
4.03M
                                   [](VExprSPtr child) { return child->is_rf_wrapper(); });
248
4.03M
    }
249
2.52k
    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
141k
    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
1.96M
    virtual const VExprSPtrs& children() const { return _children; }
281
0
    void set_children(const VExprSPtrs& children) { _children = children; }
282
628
    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
2.26M
                                                 const Selector* selector, size_t count) {
290
2.26M
        if (selector == nullptr) {
291
2.25M
            DCHECK_EQ(origin_column->size(), count) << origin_column->get_name();
292
2.25M
            return origin_column;
293
2.25M
        }
294
2.26M
        DCHECK_EQ(count, selector->size());
295
9.76k
        auto mutable_column = origin_column->clone_empty();
296
9.76k
        origin_column->append_data_by_selector(mutable_column, *selector);
297
9.76k
        DCHECK_EQ(mutable_column->size(), count);
298
9.76k
        return mutable_column;
299
2.26M
    }
300
301
0
    bool is_and_expr() const { return _fn.name.function_name == "and"; }
302
1.69k
    bool is_like_expr() const { return _fn.name.function_name == "like"; }
303
304
1.03M
    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
1.53k
    int fn_context_index() const { return _fn_context_index; }
319
320
1.51M
    static VExprSPtr expr_without_cast(const VExprSPtr& expr) {
321
1.51M
        if (expr->node_type() == TExprNodeType::CAST_EXPR) {
322
14.9k
            return expr_without_cast(expr->_children[0]);
323
14.9k
        }
324
1.49M
        return expr;
325
1.51M
    }
326
327
2.38k
    virtual double execute_cost() const {
328
2.38k
        double cost = 1.0;
329
4.52k
        for (const auto& child : _children) {
330
4.52k
            cost += child->execute_cost();
331
4.52k
        }
332
2.38k
        return cost;
333
2.38k
    }
334
335
    // If this expr is a RuntimeFilterWrapper, this method will return an underlying rf expression
336
4
    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
1.82k
    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
160
    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
24.3k
    virtual void collect_slot_column_ids(std::set<int>& column_ids) const {
357
30.4k
        for (auto child : _children) {
358
30.4k
            child->collect_slot_column_ids(column_ids);
359
30.4k
        }
360
24.3k
    }
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
494k
    std::string get_child_names() {
396
494k
        std::string res;
397
951k
        for (auto child : _children) {
398
951k
            if (!res.empty()) {
399
413k
                res += ", ";
400
413k
            }
401
951k
            res += child->expr_name();
402
951k
        }
403
494k
        return res;
404
494k
    }
405
406
    // only for errmsg now
407
2
    std::string get_child_type_names() {
408
2
        std::string res;
409
2
        for (auto child : _children) {
410
2
            if (!res.empty()) {
411
0
                res += ", ";
412
0
            }
413
2
            res += child->expr_name() + ": " + child->data_type()->get_name();
414
2
        }
415
2
        return res;
416
2
    }
417
418
708k
    bool is_const_and_have_executed() const {
419
708k
        return (is_constant() && (_constant_col != nullptr));
420
708k
    }
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
252k
                                 int scale = 0) {
472
252k
    if constexpr (T == TYPE_BOOLEAN) {
473
15
        const auto* origin_value = reinterpret_cast<const bool*>(data);
474
15
        TBoolLiteral boolLiteral;
475
15
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
476
15
        boolLiteral.__set_value(*origin_value);
477
15
        (*node).__set_bool_literal(boolLiteral);
478
15
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
479
537
    } else if constexpr (T == TYPE_TINYINT) {
480
537
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
481
537
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
482
537
        TIntLiteral intLiteral;
483
537
        intLiteral.__set_value(*origin_value);
484
537
        (*node).__set_int_literal(intLiteral);
485
537
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
486
537
    } else if constexpr (T == TYPE_SMALLINT) {
487
363
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
488
363
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
489
363
        TIntLiteral intLiteral;
490
363
        intLiteral.__set_value(*origin_value);
491
363
        (*node).__set_int_literal(intLiteral);
492
363
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
493
244k
    } else if constexpr (T == TYPE_INT) {
494
244k
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
495
244k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
496
244k
        TIntLiteral intLiteral;
497
244k
        intLiteral.__set_value(*origin_value);
498
244k
        (*node).__set_int_literal(intLiteral);
499
244k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
500
244k
    } else if constexpr (T == TYPE_BIGINT) {
501
3.40k
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
502
3.40k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
503
3.40k
        TIntLiteral intLiteral;
504
3.40k
        intLiteral.__set_value(*origin_value);
505
3.40k
        (*node).__set_int_literal(intLiteral);
506
3.40k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
507
3.40k
    } else if constexpr (T == TYPE_LARGEINT) {
508
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
509
121
        auto origin_value = unaligned_load<int128_t>(data);
510
121
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
511
121
        TLargeIntLiteral large_int_literal;
512
121
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
513
121
        (*node).__set_large_int_literal(large_int_literal);
514
121
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
515
121
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
516
92
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
517
92
        TDateLiteral date_literal;
518
92
        char convert_buffer[30];
519
92
        origin_value->to_string(convert_buffer);
520
92
        date_literal.__set_value(convert_buffer);
521
92
        (*node).__set_date_literal(date_literal);
522
92
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
523
92
        if (origin_value->type() == TimeType::TIME_DATE) {
524
43
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
525
49
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
526
49
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
527
49
        }
528
469
    } else if constexpr (T == TYPE_DATEV2) {
529
469
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
530
469
        TDateLiteral date_literal;
531
469
        char convert_buffer[30];
532
469
        origin_value->to_string(convert_buffer);
533
469
        date_literal.__set_value(convert_buffer);
534
469
        (*node).__set_date_literal(date_literal);
535
469
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
536
469
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
537
469
    } else if constexpr (T == TYPE_DATETIMEV2) {
538
205
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
539
205
        TDateLiteral date_literal;
540
205
        char convert_buffer[30];
541
205
        origin_value->to_string(convert_buffer, scale);
542
205
        date_literal.__set_value(convert_buffer);
543
205
        (*node).__set_date_literal(date_literal);
544
205
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
545
205
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
546
205
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
547
89
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
548
89
        TDateLiteral date_literal;
549
89
        auto tz = cctz::utc_time_zone();
550
89
        auto tz_str = origin_value->to_string(tz, scale);
551
89
        date_literal.__set_value(tz_str);
552
89
        (*node).__set_date_literal(date_literal);
553
89
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
554
89
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
555
89
    } 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
12
        auto origin_value = unaligned_load<DecimalV2Value>(data);
559
12
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
560
12
        TDecimalLiteral decimal_literal;
561
12
        decimal_literal.__set_value(origin_value.to_string());
562
12
        (*node).__set_decimal_literal(decimal_literal);
563
12
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
564
38
    } else if constexpr (T == TYPE_DECIMAL32) {
565
38
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
566
38
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
567
38
        TDecimalLiteral decimal_literal;
568
38
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
569
38
        (*node).__set_decimal_literal(decimal_literal);
570
38
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
571
363
    } else if constexpr (T == TYPE_DECIMAL64) {
572
363
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
573
363
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
574
363
        TDecimalLiteral decimal_literal;
575
363
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
576
363
        (*node).__set_decimal_literal(decimal_literal);
577
363
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
578
363
    } else if constexpr (T == TYPE_DECIMAL128I) {
579
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
580
178
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
581
178
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
582
178
        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
178
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
591
178
        (*node).__set_decimal_literal(decimal_literal);
592
178
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
593
458
    } else if constexpr (T == TYPE_DECIMAL256) {
594
458
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
595
458
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
596
458
        TDecimalLiteral decimal_literal;
597
458
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
598
458
        (*node).__set_decimal_literal(decimal_literal);
599
458
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
600
458
    } else if constexpr (T == TYPE_FLOAT) {
601
11
        const auto* origin_value = reinterpret_cast<const float*>(data);
602
11
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
603
11
        TFloatLiteral float_literal;
604
11
        float_literal.__set_value(*origin_value);
605
11
        (*node).__set_float_literal(float_literal);
606
11
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
607
32
    } else if constexpr (T == TYPE_DOUBLE) {
608
32
        const auto* origin_value = reinterpret_cast<const double*>(data);
609
32
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
610
32
        TFloatLiteral float_literal;
611
32
        float_literal.__set_value(*origin_value);
612
32
        (*node).__set_float_literal(float_literal);
613
32
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
614
1.41k
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
615
1.41k
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
616
1.41k
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
617
1.41k
        TStringLiteral string_literal;
618
1.41k
        string_literal.__set_value(*origin_value);
619
1.41k
        (*node).__set_string_literal(string_literal);
620
1.41k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
621
1.41k
    } else if constexpr (T == TYPE_IPV4) {
622
438
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
623
438
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
624
438
        TIPv4Literal literal;
625
438
        literal.__set_value(*origin_value);
626
438
        (*node).__set_ipv4_literal(literal);
627
438
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
628
438
    } else if constexpr (T == TYPE_IPV6) {
629
22
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
630
22
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
631
22
        TIPv6Literal literal;
632
22
        literal.__set_value(CastToString::from_ip(*origin_value));
633
22
        (*node).__set_ipv6_literal(literal);
634
22
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
635
22
    } 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
252k
    return Status::OK();
655
252k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE2EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
15
                                 int scale = 0) {
472
15
    if constexpr (T == TYPE_BOOLEAN) {
473
15
        const auto* origin_value = reinterpret_cast<const bool*>(data);
474
15
        TBoolLiteral boolLiteral;
475
15
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
476
15
        boolLiteral.__set_value(*origin_value);
477
15
        (*node).__set_bool_literal(boolLiteral);
478
15
        (*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
15
    return Status::OK();
655
15
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE3EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
537
                                 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
537
    } else if constexpr (T == TYPE_TINYINT) {
480
537
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
481
537
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
482
537
        TIntLiteral intLiteral;
483
537
        intLiteral.__set_value(*origin_value);
484
537
        (*node).__set_int_literal(intLiteral);
485
537
        (*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
537
    return Status::OK();
655
537
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE4EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
363
                                 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
363
    } else if constexpr (T == TYPE_SMALLINT) {
487
363
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
488
363
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
489
363
        TIntLiteral intLiteral;
490
363
        intLiteral.__set_value(*origin_value);
491
363
        (*node).__set_int_literal(intLiteral);
492
363
        (*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
363
    return Status::OK();
655
363
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE5EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
244k
                                 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
244k
    } else if constexpr (T == TYPE_INT) {
494
244k
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
495
244k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
496
244k
        TIntLiteral intLiteral;
497
244k
        intLiteral.__set_value(*origin_value);
498
244k
        (*node).__set_int_literal(intLiteral);
499
244k
        (*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
244k
    return Status::OK();
655
244k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE6EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
3.40k
                                 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
3.40k
    } else if constexpr (T == TYPE_BIGINT) {
501
3.40k
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
502
3.40k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
503
3.40k
        TIntLiteral intLiteral;
504
3.40k
        intLiteral.__set_value(*origin_value);
505
3.40k
        (*node).__set_int_literal(intLiteral);
506
3.40k
        (*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
3.40k
    return Status::OK();
655
3.40k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE7EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
121
                                 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
121
    } else if constexpr (T == TYPE_LARGEINT) {
508
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
509
121
        auto origin_value = unaligned_load<int128_t>(data);
510
121
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
511
121
        TLargeIntLiteral large_int_literal;
512
121
        large_int_literal.__set_value(LargeIntValue::to_string(origin_value));
513
121
        (*node).__set_large_int_literal(large_int_literal);
514
121
        (*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
121
    return Status::OK();
655
121
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE8EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
11
                                 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
11
    } else if constexpr (T == TYPE_FLOAT) {
601
11
        const auto* origin_value = reinterpret_cast<const float*>(data);
602
11
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
603
11
        TFloatLiteral float_literal;
604
11
        float_literal.__set_value(*origin_value);
605
11
        (*node).__set_float_literal(float_literal);
606
11
        (*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
11
    return Status::OK();
655
11
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE9EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
32
                                 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
32
    } else if constexpr (T == TYPE_DOUBLE) {
608
32
        const auto* origin_value = reinterpret_cast<const double*>(data);
609
32
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
610
32
        TFloatLiteral float_literal;
611
32
        float_literal.__set_value(*origin_value);
612
32
        (*node).__set_float_literal(float_literal);
613
32
        (*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
32
    return Status::OK();
655
32
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE25EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
469
                                 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
469
    } else if constexpr (T == TYPE_DATEV2) {
529
469
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
530
469
        TDateLiteral date_literal;
531
469
        char convert_buffer[30];
532
469
        origin_value->to_string(convert_buffer);
533
469
        date_literal.__set_value(convert_buffer);
534
469
        (*node).__set_date_literal(date_literal);
535
469
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
536
469
        (*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
469
    return Status::OK();
655
469
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE26EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
205
                                 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
205
    } else if constexpr (T == TYPE_DATETIMEV2) {
538
205
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
539
205
        TDateLiteral date_literal;
540
205
        char convert_buffer[30];
541
205
        origin_value->to_string(convert_buffer, scale);
542
205
        date_literal.__set_value(convert_buffer);
543
205
        (*node).__set_date_literal(date_literal);
544
205
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
545
205
        (*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
205
    return Status::OK();
655
205
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE11EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
43
                                 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
43
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
516
43
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
517
43
        TDateLiteral date_literal;
518
43
        char convert_buffer[30];
519
43
        origin_value->to_string(convert_buffer);
520
43
        date_literal.__set_value(convert_buffer);
521
43
        (*node).__set_date_literal(date_literal);
522
43
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
523
43
        if (origin_value->type() == TimeType::TIME_DATE) {
524
43
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
525
43
        } 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
43
    return Status::OK();
655
43
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE12EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
49
                                 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
49
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
516
49
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
517
49
        TDateLiteral date_literal;
518
49
        char convert_buffer[30];
519
49
        origin_value->to_string(convert_buffer);
520
49
        date_literal.__set_value(convert_buffer);
521
49
        (*node).__set_date_literal(date_literal);
522
49
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
523
49
        if (origin_value->type() == TimeType::TIME_DATE) {
524
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
525
49
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
526
49
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
527
49
        }
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
49
    return Status::OK();
655
49
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE20EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
12
                                 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
12
    } 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
12
        auto origin_value = unaligned_load<DecimalV2Value>(data);
559
12
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
560
12
        TDecimalLiteral decimal_literal;
561
12
        decimal_literal.__set_value(origin_value.to_string());
562
12
        (*node).__set_decimal_literal(decimal_literal);
563
12
        (*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
12
    return Status::OK();
655
12
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE28EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
38
                                 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
38
    } else if constexpr (T == TYPE_DECIMAL32) {
565
38
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
566
38
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
567
38
        TDecimalLiteral decimal_literal;
568
38
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
569
38
        (*node).__set_decimal_literal(decimal_literal);
570
38
        (*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
38
    return Status::OK();
655
38
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE29EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
363
                                 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
363
    } else if constexpr (T == TYPE_DECIMAL64) {
572
363
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
573
363
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
574
363
        TDecimalLiteral decimal_literal;
575
363
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
576
363
        (*node).__set_decimal_literal(decimal_literal);
577
363
        (*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
363
    return Status::OK();
655
363
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE30EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
178
                                 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
178
    } else if constexpr (T == TYPE_DECIMAL128I) {
579
        // data may not be 16-byte aligned; use unaligned_load to avoid UB.
580
178
        auto origin_value = unaligned_load<Decimal<int128_t>>(data);
581
178
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
582
178
        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
178
        decimal_literal.__set_value(origin_value.to_string(precision, scale));
591
178
        (*node).__set_decimal_literal(decimal_literal);
592
178
        (*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
178
    return Status::OK();
655
178
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE35EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
458
                                 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
458
    } else if constexpr (T == TYPE_DECIMAL256) {
594
458
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
595
458
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
596
458
        TDecimalLiteral decimal_literal;
597
458
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
598
458
        (*node).__set_decimal_literal(decimal_literal);
599
458
        (*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
458
    return Status::OK();
655
458
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE15EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
295
                                 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
295
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
615
295
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
616
295
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
617
295
        TStringLiteral string_literal;
618
295
        string_literal.__set_value(*origin_value);
619
295
        (*node).__set_string_literal(string_literal);
620
295
        (*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
295
    return Status::OK();
655
295
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE10EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
1.00k
                                 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
1.00k
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
615
1.00k
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
616
1.00k
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
617
1.00k
        TStringLiteral string_literal;
618
1.00k
        string_literal.__set_value(*origin_value);
619
1.00k
        (*node).__set_string_literal(string_literal);
620
1.00k
        (*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
1.00k
    return Status::OK();
655
1.00k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE23EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
120
                                 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
120
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
615
120
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
616
120
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
617
120
        TStringLiteral string_literal;
618
120
        string_literal.__set_value(*origin_value);
619
120
        (*node).__set_string_literal(string_literal);
620
120
        (*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
120
    return Status::OK();
655
120
}
_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
438
                                 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
438
    } else if constexpr (T == TYPE_IPV4) {
622
438
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
623
438
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
624
438
        TIPv4Literal literal;
625
438
        literal.__set_value(*origin_value);
626
438
        (*node).__set_ipv4_literal(literal);
627
438
        (*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
438
    return Status::OK();
655
438
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE37EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
471
22
                                 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
22
    } else if constexpr (T == TYPE_IPV6) {
629
22
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
630
22
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
631
22
        TIPv6Literal literal;
632
22
        literal.__set_value(CastToString::from_ip(*origin_value));
633
22
        (*node).__set_ipv6_literal(literal);
634
22
        (*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
22
    return Status::OK();
655
22
}
_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
89
                                 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
89
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
547
89
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
548
89
        TDateLiteral date_literal;
549
89
        auto tz = cctz::utc_time_zone();
550
89
        auto tz_str = origin_value->to_string(tz, scale);
551
89
        date_literal.__set_value(tz_str);
552
89
        (*node).__set_date_literal(date_literal);
553
89
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
554
89
        (*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
89
    return Status::OK();
655
89
}
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