Coverage Report

Created: 2026-02-03 22:43

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