Coverage Report

Created: 2026-06-30 15:22

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