Coverage Report

Created: 2026-02-02 23:31

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