Coverage Report

Created: 2026-07-16 14:10

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