Coverage Report

Created: 2026-07-09 03:43

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