Coverage Report

Created: 2025-12-26 22:49

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