Coverage Report

Created: 2026-02-27 11:03

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