Coverage Report

Created: 2026-05-29 11:11

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