Coverage Report

Created: 2026-06-29 11:53

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