Coverage Report

Created: 2026-04-14 10:07

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