Coverage Report

Created: 2026-07-30 13:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/root/doris/be/src/exprs/vexpr.h
Line
Count
Source
1
// Licensed to the Apache Software Foundation (ASF) under one
2
// or more contributor license agreements.  See the NOTICE file
3
// distributed with this work for additional information
4
// regarding copyright ownership.  The ASF licenses this file
5
// to you under the Apache License, Version 2.0 (the
6
// "License"); you may not use this file except in compliance
7
// with the License.  You may obtain a copy of the License at
8
//
9
//   http://www.apache.org/licenses/LICENSE-2.0
10
//
11
// Unless required by applicable law or agreed to in writing,
12
// software distributed under the License is distributed on an
13
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14
// KIND, either express or implied.  See the License for the
15
// specific language governing permissions and limitations
16
// under the License.
17
18
#pragma once
19
20
#include <gen_cpp/Exprs_types.h>
21
#include <gen_cpp/Opcodes_types.h>
22
#include <gen_cpp/Types_types.h>
23
#include <glog/logging.h>
24
25
#include <cstddef>
26
#include <cstdint>
27
#include <functional>
28
#include <memory>
29
#include <ostream>
30
#include <string>
31
#include <type_traits>
32
#include <utility>
33
#include <vector>
34
35
#include "common/be_mock_util.h"
36
#include "common/status.h"
37
#include "core/block/block.h"
38
#include "core/block/column_with_type_and_name.h"
39
#include "core/column/column.h"
40
#include "core/data_type/data_type.h"
41
#include "core/data_type/data_type_ipv6.h"
42
#include "core/data_type/define_primitive_type.h"
43
#include "core/extended_types.h"
44
#include "core/string_ref.h"
45
#include "core/types.h"
46
#include "core/value/large_int_value.h"
47
#include "core/value/timestamptz_value.h"
48
#include "exprs/aggregate/aggregate_function.h"
49
#include "exprs/expr_zonemap_filter.h"
50
#include "exprs/function/cast/cast_to_string.h"
51
#include "exprs/function/function.h"
52
#include "exprs/function_context.h"
53
#include "exprs/vexpr_fwd.h"
54
#include "storage/index/ann/ann_search_params.h"
55
#include "storage/index/index_reader.h"
56
#include "storage/index/inverted/inverted_index_reader.h"
57
#include "storage/index/zone_map/zonemap_filter_result.h"
58
#include "util/date_func.h"
59
60
namespace doris {
61
class BloomFilterFuncBase;
62
class HybridSetBase;
63
class ObjectPool;
64
class RowDescriptor;
65
class RuntimeState;
66
class ZoneMapEvalContext;
67
68
namespace segment_v2 {
69
class IndexIterator;
70
class ColumnIterator;
71
struct AnnRangeSearchRuntime;
72
}; // namespace segment_v2
73
74
#include "common/compile_check_begin.h"
75
#define RETURN_IF_ERROR_OR_PREPARED(stmt) \
76
2.73M
    if (_prepared) {                      \
77
83
        return Status::OK();              \
78
83
    }                                     \
79
2.73M
    _prepared = true;                     \
80
2.73M
    RETURN_IF_ERROR(stmt);
81
82
// VExpr should be used as shared pointer because it will be passed between classes
83
// like runtime filter to scan node, or from scannode to scanner. We could not make sure
84
// the relatioinship between threads and classes.
85
86
using Selector = IColumn::Selector;
87
using VExprCloneNodeOverride = std::function<Status(const VExpr&, VExprSPtr*)>;
88
89
struct AnnRangeSearchEvaluationResult {
90
    // Indicates whether the expr row_bitmap has been updated.
91
    bool executed = false;
92
    // Indicates whether the virtual column is fulfilled.
93
    // NOTE, if there is no virtual column in the expr tree, and expr
94
    // is evaluated by ann index, this flag is still true.
95
    bool dist_fulfilled = false;
96
};
97
98
class VExpr {
99
public:
100
    // resize inserted param column to make sure column size equal to block.rows() and return param column index
101
    // keep return type same with block::columns()
102
598
    static uint32_t insert_param(Block* block, ColumnWithTypeAndName&& elem, size_t size) {
103
        // usually elem.column always is const column, so we just clone it.
104
598
        elem.column = elem.column->clone_resized(size);
105
598
        block->insert(std::move(elem));
106
        // just inserted. so no need to check underflow.
107
598
        return block->columns() - 1;
108
598
    }
109
110
    static bool is_acting_on_a_slot(const VExpr& expr);
111
112
    VExpr(const TExprNode& node);
113
    VExpr(const VExpr& vexpr);
114
    VExpr(DataTypePtr type, bool is_slotref);
115
    // only used for test
116
1.41k
    VExpr() = default;
117
7.69M
    virtual ~VExpr() = default;
118
119
    virtual const std::string& expr_name() const = 0;
120
0
    virtual std::string expr_label() { return ""; }
121
122
    /// Initializes this expr instance for execution. This does not include initializing
123
    /// state in the VExprContext; 'context' should only be used to register a
124
    /// FunctionContext via RegisterFunctionContext().
125
    ///
126
    /// Subclasses overriding this function should call VExpr::Prepare() to recursively call
127
    /// Prepare() on the expr tree
128
    /// row_desc used in vslot_ref and some subclass to specify column
129
    virtual Status prepare(RuntimeState* state, const RowDescriptor& row_desc,
130
                           VExprContext* context);
131
132
    /// Initializes 'context' for execution. If scope if FRAGMENT_LOCAL, both fragment- and
133
    /// thread-local state should be initialized. Otherwise, if scope is THREAD_LOCAL, only
134
    /// thread-local state should be initialized.
135
    //
136
    /// Subclasses overriding this function should call VExpr::Open() to recursively call
137
    /// Open() on the expr tree
138
    virtual Status open(RuntimeState* state, VExprContext* context,
139
                        FunctionContext::FunctionStateScope scope);
140
141
    // before execute, check if expr has been parepared+opened.
142
0
    [[maybe_unused]] Status ready_status() const {
143
0
        if (_prepare_finished && _open_finished) {
144
0
            return Status::OK();
145
0
        }
146
0
        return Status::InternalError(expr_name() + " is not ready when execute");
147
0
    }
148
149
49.8k
    virtual Status execute(VExprContext* context, Block* block, int* result_column_id) const {
150
49.8k
        ColumnPtr result_column;
151
49.8k
        RETURN_IF_ERROR(execute_column(context, block, nullptr, block->rows(), result_column));
152
49.8k
        *result_column_id = block->columns();
153
49.8k
        block->insert({result_column, execute_type(block), expr_name()});
154
49.8k
        return Status::OK();
155
49.8k
    }
156
157
    // Execute the current expression and return the result column.
158
    // Note: the block will not be modified during execution.
159
    // We allow columns in the block to have different numbers of rows.
160
    // 'count' indicates the number of rows in the result column returned by this expression.
161
    // In the future this interface will add an additional parameter, Selector, which specifies
162
    // which rows in the block should be evaluated.
163
    // If expr is executing constant expressions, then block should be nullptr.
164
    virtual Status execute_column(VExprContext* context, const Block* block, Selector* selector,
165
377
                                  size_t count, ColumnPtr& result_column) const {
166
377
        return execute_column_impl(context, block, selector, count, result_column);
167
377
    }
168
169
    template <typename SelectorType, std::enable_if_t<std::is_const_v<SelectorType>, int> = 0>
170
    Status execute_column(VExprContext* context, const Block* block, SelectorType* selector,
171
143
                          size_t count, ColumnPtr& result_column) const {
172
        // format_v2 treats selectors as read-only; the branch-4.1 expression API still exposes
173
        // a mutable pointer even though implementations must not modify it.
174
143
        return execute_column(context, block, const_cast<Selector*>(selector), count,
175
143
                              result_column);
176
143
    }
177
178
    virtual Status execute_column_impl(VExprContext* context, const Block* block,
179
                                       const Selector* selector, size_t count,
180
9
                                       ColumnPtr& result_column) const {
181
9
        return execute_column(context, block, const_cast<Selector*>(selector), count,
182
9
                              result_column);
183
9
    }
184
185
    // Currently, due to fe planning issues, for slot-ref expressions the type of the returned Column may not match data_type.
186
    // Therefore we need a function like this to return the actual type produced by execution.
187
1.59M
    virtual DataTypePtr execute_type(const Block* block) const { return _data_type; }
188
189
    virtual Status execute_filter(VExprContext* context, const Block* block,
190
                                  uint8_t* __restrict result_filter_data, size_t rows,
191
                                  bool accept_null, bool* can_filter_all) const;
192
193
    // Raw fixed-width evaluation is an optional expression capability used before a storage reader
194
    // materializes a column. The capability query must validate the bound slot and logical type and
195
    // remain stable for the reader lifetime. Execution receives `num_values` tightly packed,
196
    // non-NULL logical values of `value_width` bytes; it ANDs decisions into the caller-owned
197
    // `matches` array and must leave already rejected rows rejected. Callers handle NULL rows from
198
    // definition levels because the physical value stream has no payload for them.
199
    virtual bool can_execute_on_raw_fixed_values(const DataTypePtr& data_type,
200
73
                                                 int column_id) const {
201
73
        return false;
202
73
    }
203
    virtual Status execute_on_raw_fixed_values(const uint8_t* values, size_t num_values,
204
                                               size_t value_width, const DataTypePtr& data_type,
205
0
                                               int column_id, uint8_t* matches) const {
206
0
        return Status::NotSupported("{} cannot evaluate raw fixed-width values", expr_name());
207
0
    }
208
209
    // Variable-width Parquet decoders expose `num_values` immutable, non-NULL slices rather than an
210
    // IColumn. The capability query must validate the bound slot and logical type. Execution may
211
    // borrow each slice only for the duration of the call and must AND its decisions into `matches`;
212
    // expressions opt in only when Doris semantics are identical to comparing the decoded bytes.
213
    virtual bool can_execute_on_raw_binary_values(const DataTypePtr& data_type,
214
59
                                                  int column_id) const {
215
59
        return false;
216
59
    }
217
    virtual Status execute_on_raw_binary_values(const StringRef* values, size_t num_values,
218
                                                const DataTypePtr& data_type, int column_id,
219
0
                                                uint8_t* matches) const {
220
0
        return Status::NotSupported("{} cannot evaluate raw binary values", expr_name());
221
0
    }
222
223
    // Returns the Boolean result for a logical NULL whose payload is absent from decoder value
224
    // callbacks. Most raw predicates reject NULL; dynamic predicates override this hook when
225
    // their current runtime state can admit it.
226
320
    virtual bool raw_predicate_result_for_null() const { return false; }
227
228
    // Parquet NULLs have no value payload. Level-aware predicates consume the definition-level
229
    // null map directly instead of forcing the reader to fabricate a nullable Doris column.
230
194
    virtual bool can_execute_on_null_map(const DataTypePtr& data_type, int column_id) const {
231
194
        return false;
232
194
    }
233
    virtual Status execute_on_null_map(const uint8_t* null_map, size_t num_values,
234
                                       const DataTypePtr& data_type, int column_id,
235
0
                                       uint8_t* matches) const {
236
0
        return Status::NotSupported("{} cannot evaluate a NULL map", expr_name());
237
0
    }
238
239
    // Typed reader evaluation is an optional capability for runtime-filter wrappers. It lets a
240
    // storage reader consume converted logical values without scheduling the same expression on
241
    // a materialized file block afterwards.
242
0
    virtual bool can_execute_on_reader_values(const DataTypePtr& data_type, int column_id) const {
243
0
        return false;
244
0
    }
245
246
    // `is_blockable` means this expr will be blocked in `execute` (e.g. AI Function, Remote Function)
247
3.34M
    [[nodiscard]] virtual bool is_blockable() const {
248
3.34M
        return std::any_of(_children.begin(), _children.end(),
249
3.34M
                           [](VExprSPtr child) { return child->is_blockable(); });
250
3.34M
    }
251
252
1.15k
    [[nodiscard]] virtual bool is_deterministic() const {
253
1.15k
        return std::ranges::all_of(
254
1.15k
                _children, [](const VExprSPtr& child) { return child->is_deterministic(); });
255
1.15k
    }
256
257
462
    [[nodiscard]] virtual bool is_safe_to_execute_on_selected_rows() const {
258
462
        return is_deterministic() && std::ranges::all_of(_children, [](const VExprSPtr& child) {
259
257
                   return child->is_safe_to_execute_on_selected_rows();
260
257
               });
261
462
    }
262
263
    // execute current expr with inverted index to filter block. Given a roaring bitmap of match rows
264
783
    virtual Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) {
265
783
        return Status::OK();
266
783
    }
267
268
    virtual ZoneMapFilterResult evaluate_zonemap_filter(const ZoneMapEvalContext& ctx) const;
269
10.9k
    virtual bool can_evaluate_zonemap_filter() const { return false; }
270
    // Dictionary evaluation is an optional conservative pruning capability over non-NULL values.
271
    // kNoMatch proves that no dictionary entry can satisfy the expression, kMayMatch means at least
272
    // one entry may satisfy it (or pruning cannot currently disprove it), and kUnsupported means the
273
    // context lacks a compatible binding. Capability must describe expression shape, not the
274
    // current contents of a late-arriving runtime filter, because readers may cache it.
275
    virtual ZoneMapFilterResult evaluate_dictionary_filter(const DictionaryEvalContext& ctx) const;
276
98
    virtual bool can_evaluate_dictionary_filter() const { return false; }
277
    virtual ZoneMapFilterResult evaluate_bloom_filter(const BloomFilterEvalContext& ctx) const;
278
89
    virtual bool can_evaluate_bloom_filter() const { return false; }
279
280
    // Get analyzer key for inverted index queries (overridden by VMatchPredicate)
281
0
    [[nodiscard]] virtual const std::string& get_analyzer_key() const {
282
0
        static const std::string empty;
283
0
        return empty;
284
0
    }
285
286
    Status _evaluate_inverted_index(VExprContext* context, const FunctionBasePtr& function,
287
                                    uint32_t segment_num_rows);
288
289
    virtual size_t estimate_memory(const size_t rows);
290
291
    // Only the 4th parameter is used in the runtime filter. In and MinMax need overwrite the
292
    // interface
293
    virtual Status execute_runtime_filter(VExprContext* context, const Block* block,
294
                                          const uint8_t* __restrict filter, size_t count,
295
1
                                          ColumnPtr& result_column, ColumnPtr* arg_column) const {
296
1
        return execute_column(context, block, nullptr, count, result_column);
297
1
    };
298
299
    /// Subclasses overriding this function should call VExpr::Close().
300
    //
301
    /// If scope if FRAGMENT_LOCAL, both fragment- and thread-local state should be torn
302
    /// down. Otherwise, if scope is THREAD_LOCAL, only thread-local state should be torn
303
    /// down.
304
    virtual void close(VExprContext* context, FunctionContext::FunctionStateScope scope);
305
306
14.8M
    DataTypePtr& data_type() { return _data_type; }
307
308
7.37k
    const DataTypePtr& data_type() const { return _data_type; }
309
310
200k
    virtual bool is_slot_ref() const { return _node_type == TExprNodeType::SLOT_REF; }
311
312
53.7k
    virtual bool is_virtual_slot_ref() const {
313
53.7k
        return _node_type == TExprNodeType::VIRTUAL_SLOT_REF;
314
53.7k
    }
315
316
281
    virtual bool is_column_ref() const { return _node_type == TExprNodeType::COLUMN_REF; }
317
318
568k
    virtual bool is_literal() const { return false; }
319
320
4.43M
    virtual TExprNodeType::type node_type() const { return _node_type; }
321
322
39.7k
    TExprOpcode::type op() const { return _opcode; }
323
324
1.41M
    void add_child(const VExprSPtr& expr) { _children.push_back(expr); }
325
54.5k
    VExprSPtr get_child(uint16_t i) const { return _children[i]; }
326
    // Expr's children number is restricted by org.apache.doris.common.Config#expr_children_limit, 10000 default. and strongly not recommend to change.
327
    // There's little to worry about it. uint16 is enough.
328
423k
    uint16_t get_num_children() const { return static_cast<uint16_t>(_children.size()); }
329
330
4.82M
    virtual bool is_rf_wrapper() const {
331
4.82M
        return std::ranges::any_of(_children.begin(), _children.end(),
332
4.82M
                                   [](VExprSPtr child) { return child->is_rf_wrapper(); });
333
4.82M
    }
334
2.09k
    virtual bool is_topn_filter() const { return false; }
335
336
    static Status create_expr_tree(const TExpr& texpr, VExprContextSPtr& ctx);
337
338
    static Status create_expr_trees(const std::vector<TExpr>& texprs, VExprContextSPtrs& ctxs);
339
340
    static Status prepare(const VExprContextSPtrs& ctxs, RuntimeState* state,
341
                          const RowDescriptor& row_desc);
342
343
    static Status open(const VExprContextSPtrs& ctxs, RuntimeState* state);
344
345
    static Status clone_if_not_exists(const VExprContextSPtrs& ctxs, RuntimeState* state,
346
                                      VExprContextSPtrs& new_ctxs);
347
348
    static bool contains_blockable_function(const VExprContextSPtrs& ctxs);
349
350
    Status deep_clone(VExprSPtr* cloned_expr,
351
                      const VExprCloneNodeOverride& clone_node_override = {}) const;
352
    virtual Status clone_node(VExprSPtr* cloned_expr) const;
353
354
159k
    bool is_nullable() const { return _data_type->is_nullable(); }
355
356
0
    PrimitiveType result_type() const { return _data_type->get_primitive_type(); }
357
358
    static Status create_expr(const TExprNode& expr_node, VExprSPtr& expr);
359
360
    static Status create_tree_from_thrift(const std::vector<TExprNode>& nodes, int* node_idx,
361
                                          VExprSPtr& root_expr, VExprContextSPtr& ctx);
362
363
    static Status check_expr_output_type(const VExprContextSPtrs& ctxs,
364
                                         const RowDescriptor& output_row_desc);
365
2.56M
    virtual const VExprSPtrs& children() const { return _children; }
366
0
    void set_children(const VExprSPtrs& children) { _children = children; }
367
849
    void set_children(VExprSPtrs&& children) { _children = std::move(children); }
368
    void reset_prepare_state();
369
    virtual std::string debug_string() const;
370
    static std::string debug_string(const VExprSPtrs& exprs);
371
    static std::string debug_string(const VExprContextSPtrs& ctxs);
372
373
    static ColumnPtr filter_column_with_selector(const ColumnPtr& origin_column,
374
2.12M
                                                 const Selector* selector, size_t count) {
375
2.12M
        if (selector == nullptr) {
376
2.12M
            DCHECK_EQ(origin_column->size(), count) << origin_column->get_name();
377
2.12M
            return origin_column;
378
2.12M
        }
379
2.12M
        DCHECK_EQ(count, selector->size());
380
1.73k
        auto mutable_column = origin_column->clone_empty();
381
1.73k
        origin_column->append_data_by_selector(mutable_column, *selector);
382
1.73k
        DCHECK_EQ(mutable_column->size(), count);
383
1.73k
        return mutable_column;
384
2.12M
    }
385
386
0
    bool is_and_expr() const { return _fn.name.function_name == "and"; }
387
1.44k
    bool is_like_expr() const { return _fn.name.function_name == "like"; }
388
389
1.26M
    const TFunction& fn() const { return _fn; }
390
391
    /// Returns true if expr doesn't contain slotrefs, i.e., can be evaluated
392
    /// with get_value(NULL). The default implementation returns true if all of
393
    /// the children are constant.
394
    virtual bool is_constant() const;
395
396
    /// If this expr is constant, evaluates the expr with no input row argument and returns
397
    /// the output. Returns nullptr if the argument is not constant. The returned ColumnPtr is
398
    /// owned by this expr. This should only be called after Open() has been called on this
399
    /// expr.
400
    MOCK_FUNCTION Status get_const_col(VExprContext* context,
401
                                       std::shared_ptr<ColumnPtrWrapper>* column_wrapper);
402
403
1.44k
    int fn_context_index() const { return _fn_context_index; }
404
405
2.03M
    static VExprSPtr expr_without_cast(const VExprSPtr& expr) {
406
2.03M
        if (expr->node_type() == TExprNodeType::CAST_EXPR) {
407
12.2k
            return expr_without_cast(expr->_children[0]);
408
12.2k
        }
409
2.01M
        return expr;
410
2.03M
    }
411
412
6.01k
    virtual double execute_cost() const {
413
6.01k
        double cost = 1.0;
414
8.07k
        for (const auto& child : _children) {
415
8.07k
            cost += child->execute_cost();
416
8.07k
        }
417
6.01k
        return cost;
418
6.01k
    }
419
420
    // If this expr is a RuntimeFilterWrapper, this method will return an underlying rf expression
421
183
    virtual VExprSPtr get_impl() const { return {}; }
422
423
    // If this expr is a BloomPredicate, this method will return a BloomFilterFunc
424
0
    virtual std::shared_ptr<BloomFilterFuncBase> get_bloom_filter_func() const {
425
0
        throw Exception(Status::FatalError(
426
0
                "Method 'get_bloom_filter_func()' is not supported in expression: {}",
427
0
                this->debug_string()));
428
0
    }
429
430
1.26k
    virtual std::shared_ptr<HybridSetBase> get_set_func() const { return nullptr; }
431
432
    // fast_execute can direct copy expr filter result which build by apply index in segment_iterator
433
    bool fast_execute(VExprContext* context, Selector* selector, size_t count,
434
                      ColumnPtr& result_column) const;
435
436
151
    virtual bool can_push_down_to_index() const { return false; }
437
    virtual bool equals(const VExpr& other);
438
0
    void set_index_unique_id(uint32_t index_unique_id) { _index_unique_id = index_unique_id; }
439
0
    uint32_t index_unique_id() const { return _index_unique_id; }
440
441
22.0k
    virtual void collect_slot_column_ids(std::set<int>& column_ids) const {
442
27.0k
        for (auto child : _children) {
443
27.0k
            child->collect_slot_column_ids(column_ids);
444
27.0k
        }
445
22.0k
    }
446
447
#ifdef BE_TEST
448
    void set_node_type(TExprNodeType::type node_type) { _node_type = node_type; }
449
#endif
450
    virtual Status evaluate_ann_range_search(
451
            const segment_v2::AnnRangeSearchRuntime& runtime,
452
            const std::vector<std::unique_ptr<segment_v2::IndexIterator>>& cid_to_index_iterators,
453
            const std::vector<ColumnId>& idx_to_cid,
454
            const std::vector<std::unique_ptr<segment_v2::ColumnIterator>>& column_iterators,
455
            size_t rows_of_segment, roaring::Roaring& row_bitmap,
456
            segment_v2::AnnIndexStats& ann_index_stats, AnnRangeSearchEvaluationResult& result);
457
458
    // Prepare the runtime for ANN range search.
459
    // AnnRangeSearchRuntime is used to store the runtime information of ann range search.
460
    // suitable_for_ann_index is used to indicate whether the current expr can be used for ANN range search.
461
    // If suitable_for_ann_index is false, the we will do exhausted search.
462
    virtual void prepare_ann_range_search(const doris::VectorSearchUserParams& params,
463
                                          segment_v2::AnnRangeSearchRuntime& range_search_runtime,
464
                                          bool& suitable_for_ann_index);
465
466
    virtual uint64_t get_digest(uint64_t seed) const;
467
468
protected:
469
    TExprNode clone_texpr_node() const;
470
471
    /// Simple debug string that provides no expr subclass-specific information
472
0
    std::string debug_string(const std::string& expr_name) const {
473
0
        std::stringstream out;
474
0
        out << expr_name << "(" << VExpr::debug_string() << ")";
475
0
        return out.str();
476
0
    }
477
478
    // used in expr name
479
549k
    std::string get_child_names() {
480
549k
        std::string res;
481
1.06M
        for (auto child : _children) {
482
1.06M
            if (!res.empty()) {
483
474k
                res += ", ";
484
474k
            }
485
1.06M
            res += child->expr_name();
486
1.06M
        }
487
549k
        return res;
488
549k
    }
489
490
    // only for errmsg now
491
2
    std::string get_child_type_names() {
492
2
        std::string res;
493
2
        for (auto child : _children) {
494
2
            if (!res.empty()) {
495
0
                res += ", ";
496
0
            }
497
2
            res += child->expr_name() + ": " + child->data_type()->get_name();
498
2
        }
499
2
        return res;
500
2
    }
501
502
648k
    bool is_const_and_have_executed() const {
503
648k
        return (is_constant() && (_constant_col != nullptr));
504
648k
    }
505
506
    ColumnPtr get_result_from_const(size_t count) const;
507
508
    Status check_constant(const Block& block, ColumnNumbers arguments) const;
509
510
    /// Helper function that calls ctx->register(), sets fn_context_index_, and returns the
511
    /// registered FunctionContext
512
    void register_function_context(RuntimeState* state, VExprContext* context);
513
514
    /// Helper function to initialize function context, called in `open` phase of VExpr:
515
    /// 1. Set constant columns result of function arguments.
516
    /// 2. Call function's prepare() to initialize function state, fragment-local or
517
    /// thread-local according the input `FunctionStateScope` argument.
518
    Status init_function_context(RuntimeState* state, VExprContext* context,
519
                                 FunctionContext::FunctionStateScope scope,
520
                                 const FunctionBasePtr& function) const;
521
522
    /// Helper function to close function context, fragment-local or thread-local according
523
    /// the input `FunctionStateScope` argument. Called in `close` phase of VExpr.
524
    void close_function_context(VExprContext* context, FunctionContext::FunctionStateScope scope,
525
                                const FunctionBasePtr& function) const;
526
527
    TExprNodeType::type _node_type;
528
    // Used to check what opcode
529
    TExprOpcode::type _opcode;
530
    DataTypePtr _data_type;
531
    VExprSPtrs _children; // in few hundreds
532
    TFunction _fn;
533
534
    /// Index to pass to ExprContext::fn_context() to retrieve this expr's FunctionContext.
535
    /// Set in RegisterFunctionContext(). -1 if this expr does not need a FunctionContext and
536
    /// doesn't call RegisterFunctionContext().
537
    int _fn_context_index = -1;
538
539
    // If this expr is constant, this will store and cache the value generated by
540
    // get_const_col()
541
    std::shared_ptr<ColumnPtrWrapper> _constant_col;
542
    bool _prepared = false; // for base class VExpr
543
    // for concrete classes
544
    bool _prepare_finished = false;
545
    bool _open_finished = false;
546
547
    // ensuring uniqueness during index traversal
548
    uint32_t _index_unique_id = 0;
549
    bool _enable_inverted_index_query = true;
550
};
551
552
// NOLINTBEGIN(readability-function-size)
553
template <PrimitiveType T>
554
Status create_texpr_literal_node(const void* data, TExprNode* node, int precision = 0,
555
398k
                                 int scale = 0) {
556
398k
    if constexpr (T == TYPE_BOOLEAN) {
557
17
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
17
        TBoolLiteral boolLiteral;
559
17
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
17
        boolLiteral.__set_value(*origin_value);
561
17
        (*node).__set_bool_literal(boolLiteral);
562
17
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
785
    } else if constexpr (T == TYPE_TINYINT) {
564
785
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
785
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
785
        TIntLiteral intLiteral;
567
785
        intLiteral.__set_value(*origin_value);
568
785
        (*node).__set_int_literal(intLiteral);
569
785
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
785
    } else if constexpr (T == TYPE_SMALLINT) {
571
441
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
441
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
441
        TIntLiteral intLiteral;
574
441
        intLiteral.__set_value(*origin_value);
575
441
        (*node).__set_int_literal(intLiteral);
576
441
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
349k
    } else if constexpr (T == TYPE_INT) {
578
349k
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
349k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
349k
        TIntLiteral intLiteral;
581
349k
        intLiteral.__set_value(*origin_value);
582
349k
        (*node).__set_int_literal(intLiteral);
583
349k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
349k
    } else if constexpr (T == TYPE_BIGINT) {
585
43.6k
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
43.6k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
43.6k
        TIntLiteral intLiteral;
588
43.6k
        intLiteral.__set_value(*origin_value);
589
43.6k
        (*node).__set_int_literal(intLiteral);
590
43.6k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
43.6k
    } else if constexpr (T == TYPE_LARGEINT) {
592
26
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
26
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
26
        TLargeIntLiteral large_int_literal;
595
26
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
26
        (*node).__set_large_int_literal(large_int_literal);
597
26
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
92
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
92
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
92
        TDateLiteral date_literal;
601
92
        char convert_buffer[30];
602
92
        origin_value->to_string(convert_buffer);
603
92
        date_literal.__set_value(convert_buffer);
604
92
        (*node).__set_date_literal(date_literal);
605
92
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
92
        if (origin_value->type() == TimeType::TIME_DATE) {
607
35
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
57
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
57
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
57
        }
611
400
    } else if constexpr (T == TYPE_DATEV2) {
612
400
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
400
        TDateLiteral date_literal;
614
400
        char convert_buffer[30];
615
400
        origin_value->to_string(convert_buffer);
616
400
        date_literal.__set_value(convert_buffer);
617
400
        (*node).__set_date_literal(date_literal);
618
400
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
400
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
400
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
176
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
176
        TDateLiteral date_literal;
623
176
        char convert_buffer[30];
624
176
        origin_value->to_string(convert_buffer, scale);
625
176
        date_literal.__set_value(convert_buffer);
626
176
        (*node).__set_date_literal(date_literal);
627
176
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
176
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
176
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
77
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
77
        TDateLiteral date_literal;
632
77
        auto tz = cctz::utc_time_zone();
633
77
        auto tz_str = origin_value->to_string(tz, scale);
634
77
        date_literal.__set_value(tz_str);
635
77
        (*node).__set_date_literal(date_literal);
636
77
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
77
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
77
    } else if constexpr (T == TYPE_DECIMALV2) {
639
17
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
17
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
17
        TDecimalLiteral decimal_literal;
642
17
        decimal_literal.__set_value(origin_value->to_string());
643
17
        (*node).__set_decimal_literal(decimal_literal);
644
17
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
24
    } else if constexpr (T == TYPE_DECIMAL32) {
646
24
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
24
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
24
        TDecimalLiteral decimal_literal;
649
24
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
24
        (*node).__set_decimal_literal(decimal_literal);
651
24
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
500
    } else if constexpr (T == TYPE_DECIMAL64) {
653
500
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
500
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
500
        TDecimalLiteral decimal_literal;
656
500
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
500
        (*node).__set_decimal_literal(decimal_literal);
658
500
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
500
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
112
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
112
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
112
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
112
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
112
        (*node).__set_decimal_literal(decimal_literal);
672
112
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
262
    } else if constexpr (T == TYPE_DECIMAL256) {
674
262
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
262
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
262
        TDecimalLiteral decimal_literal;
677
262
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
262
        (*node).__set_decimal_literal(decimal_literal);
679
262
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
262
    } else if constexpr (T == TYPE_FLOAT) {
681
9
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
9
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
9
        TFloatLiteral float_literal;
684
9
        float_literal.__set_value(*origin_value);
685
9
        (*node).__set_float_literal(float_literal);
686
9
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
45
    } else if constexpr (T == TYPE_DOUBLE) {
688
45
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
45
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
45
        TFloatLiteral float_literal;
691
45
        float_literal.__set_value(*origin_value);
692
45
        (*node).__set_float_literal(float_literal);
693
45
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
1.73k
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
1.73k
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
1.73k
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
1.73k
        TStringLiteral string_literal;
698
1.73k
        string_literal.__set_value(*origin_value);
699
1.73k
        (*node).__set_string_literal(string_literal);
700
1.73k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
1.73k
    } else if constexpr (T == TYPE_IPV4) {
702
271
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
271
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
271
        TIPv4Literal literal;
705
271
        literal.__set_value(*origin_value);
706
271
        (*node).__set_ipv4_literal(literal);
707
271
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
271
    } else if constexpr (T == TYPE_IPV6) {
709
28
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
28
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
28
        TIPv6Literal literal;
712
28
        literal.__set_value(CastToString::from_ip(*origin_value));
713
28
        (*node).__set_ipv6_literal(literal);
714
28
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
28
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
1
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
1
        TTimeV2Literal timev2_literal;
719
1
        timev2_literal.__set_value(*origin_value);
720
1
        (*node).__set_timev2_literal(timev2_literal);
721
1
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
1
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
1
    } else if constexpr (T == TYPE_VARBINARY) {
724
0
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
0
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
0
        TVarBinaryLiteral varbinary_literal;
727
0
        varbinary_literal.__set_value(*origin_value);
728
0
        (*node).__set_varbinary_literal(varbinary_literal);
729
0
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
398k
    return Status::OK();
734
398k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE2EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
17
                                 int scale = 0) {
556
17
    if constexpr (T == TYPE_BOOLEAN) {
557
17
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
17
        TBoolLiteral boolLiteral;
559
17
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
17
        boolLiteral.__set_value(*origin_value);
561
17
        (*node).__set_bool_literal(boolLiteral);
562
17
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
17
    return Status::OK();
734
17
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE3EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
785
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
785
    } else if constexpr (T == TYPE_TINYINT) {
564
785
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
785
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
785
        TIntLiteral intLiteral;
567
785
        intLiteral.__set_value(*origin_value);
568
785
        (*node).__set_int_literal(intLiteral);
569
785
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
785
    return Status::OK();
734
785
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE4EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
441
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
441
    } else if constexpr (T == TYPE_SMALLINT) {
571
441
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
441
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
441
        TIntLiteral intLiteral;
574
441
        intLiteral.__set_value(*origin_value);
575
441
        (*node).__set_int_literal(intLiteral);
576
441
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
441
    return Status::OK();
734
441
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE5EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
349k
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
349k
    } else if constexpr (T == TYPE_INT) {
578
349k
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
349k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
349k
        TIntLiteral intLiteral;
581
349k
        intLiteral.__set_value(*origin_value);
582
349k
        (*node).__set_int_literal(intLiteral);
583
349k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
349k
    return Status::OK();
734
349k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE6EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
43.6k
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
43.6k
    } else if constexpr (T == TYPE_BIGINT) {
585
43.6k
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
43.6k
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
43.6k
        TIntLiteral intLiteral;
588
43.6k
        intLiteral.__set_value(*origin_value);
589
43.6k
        (*node).__set_int_literal(intLiteral);
590
43.6k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
43.6k
    return Status::OK();
734
43.6k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE7EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
26
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
26
    } else if constexpr (T == TYPE_LARGEINT) {
592
26
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
26
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
26
        TLargeIntLiteral large_int_literal;
595
26
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
26
        (*node).__set_large_int_literal(large_int_literal);
597
26
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
26
    return Status::OK();
734
26
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE8EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
9
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
9
    } else if constexpr (T == TYPE_FLOAT) {
681
9
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
9
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
9
        TFloatLiteral float_literal;
684
9
        float_literal.__set_value(*origin_value);
685
9
        (*node).__set_float_literal(float_literal);
686
9
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
9
    return Status::OK();
734
9
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE9EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
45
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
45
    } else if constexpr (T == TYPE_DOUBLE) {
688
45
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
45
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
45
        TFloatLiteral float_literal;
691
45
        float_literal.__set_value(*origin_value);
692
45
        (*node).__set_float_literal(float_literal);
693
45
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
45
    return Status::OK();
734
45
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE25EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
400
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
400
    } else if constexpr (T == TYPE_DATEV2) {
612
400
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
400
        TDateLiteral date_literal;
614
400
        char convert_buffer[30];
615
400
        origin_value->to_string(convert_buffer);
616
400
        date_literal.__set_value(convert_buffer);
617
400
        (*node).__set_date_literal(date_literal);
618
400
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
400
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
400
    return Status::OK();
734
400
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE26EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
176
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
176
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
176
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
176
        TDateLiteral date_literal;
623
176
        char convert_buffer[30];
624
176
        origin_value->to_string(convert_buffer, scale);
625
176
        date_literal.__set_value(convert_buffer);
626
176
        (*node).__set_date_literal(date_literal);
627
176
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
176
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
176
    return Status::OK();
734
176
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE11EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
35
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
35
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
35
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
35
        TDateLiteral date_literal;
601
35
        char convert_buffer[30];
602
35
        origin_value->to_string(convert_buffer);
603
35
        date_literal.__set_value(convert_buffer);
604
35
        (*node).__set_date_literal(date_literal);
605
35
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
35
        if (origin_value->type() == TimeType::TIME_DATE) {
607
35
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
35
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
0
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
35
    return Status::OK();
734
35
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE12EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
57
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
57
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
57
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
57
        TDateLiteral date_literal;
601
57
        char convert_buffer[30];
602
57
        origin_value->to_string(convert_buffer);
603
57
        date_literal.__set_value(convert_buffer);
604
57
        (*node).__set_date_literal(date_literal);
605
57
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
57
        if (origin_value->type() == TimeType::TIME_DATE) {
607
0
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
57
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
57
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
57
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
57
    return Status::OK();
734
57
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE20EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
17
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
17
    } else if constexpr (T == TYPE_DECIMALV2) {
639
17
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
17
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
17
        TDecimalLiteral decimal_literal;
642
17
        decimal_literal.__set_value(origin_value->to_string());
643
17
        (*node).__set_decimal_literal(decimal_literal);
644
17
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
17
    return Status::OK();
734
17
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE28EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
24
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
24
    } else if constexpr (T == TYPE_DECIMAL32) {
646
24
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
24
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
24
        TDecimalLiteral decimal_literal;
649
24
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
24
        (*node).__set_decimal_literal(decimal_literal);
651
24
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
24
    return Status::OK();
734
24
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE29EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
500
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
500
    } else if constexpr (T == TYPE_DECIMAL64) {
653
500
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
500
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
500
        TDecimalLiteral decimal_literal;
656
500
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
500
        (*node).__set_decimal_literal(decimal_literal);
658
500
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
500
    return Status::OK();
734
500
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE30EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
112
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
112
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
112
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
112
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
112
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
112
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
112
        (*node).__set_decimal_literal(decimal_literal);
672
112
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
112
    return Status::OK();
734
112
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE35EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
262
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
262
    } else if constexpr (T == TYPE_DECIMAL256) {
674
262
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
262
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
262
        TDecimalLiteral decimal_literal;
677
262
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
262
        (*node).__set_decimal_literal(decimal_literal);
679
262
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
262
    return Status::OK();
734
262
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE15EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
444
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
444
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
444
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
444
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
444
        TStringLiteral string_literal;
698
444
        string_literal.__set_value(*origin_value);
699
444
        (*node).__set_string_literal(string_literal);
700
444
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
444
    return Status::OK();
734
444
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE10EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
1.17k
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
1.17k
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
1.17k
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
1.17k
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
1.17k
        TStringLiteral string_literal;
698
1.17k
        string_literal.__set_value(*origin_value);
699
1.17k
        (*node).__set_string_literal(string_literal);
700
1.17k
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
1.17k
    return Status::OK();
734
1.17k
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE23EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
116
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
116
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
116
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
116
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
116
        TStringLiteral string_literal;
698
116
        string_literal.__set_value(*origin_value);
699
116
        (*node).__set_string_literal(string_literal);
700
116
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
116
    return Status::OK();
734
116
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE36EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
271
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
271
    } else if constexpr (T == TYPE_IPV4) {
702
271
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
271
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
271
        TIPv4Literal literal;
705
271
        literal.__set_value(*origin_value);
706
271
        (*node).__set_ipv4_literal(literal);
707
271
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
271
    return Status::OK();
734
271
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE37EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
28
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
28
    } else if constexpr (T == TYPE_IPV6) {
709
28
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
28
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
28
        TIPv6Literal literal;
712
28
        literal.__set_value(CastToString::from_ip(*origin_value));
713
28
        (*node).__set_ipv6_literal(literal);
714
28
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
28
    return Status::OK();
734
28
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE27EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
1
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
        TDateLiteral date_literal;
632
        auto tz = cctz::utc_time_zone();
633
        auto tz_str = origin_value->to_string(tz, scale);
634
        date_literal.__set_value(tz_str);
635
        (*node).__set_date_literal(date_literal);
636
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
1
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
1
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
1
        TTimeV2Literal timev2_literal;
719
1
        timev2_literal.__set_value(*origin_value);
720
1
        (*node).__set_timev2_literal(timev2_literal);
721
1
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
1
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
1
    return Status::OK();
734
1
}
_ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE42EEENS_6StatusEPKvPNS_9TExprNodeEii
Line
Count
Source
555
77
                                 int scale = 0) {
556
    if constexpr (T == TYPE_BOOLEAN) {
557
        const auto* origin_value = reinterpret_cast<const bool*>(data);
558
        TBoolLiteral boolLiteral;
559
        (*node).__set_node_type(TExprNodeType::BOOL_LITERAL);
560
        boolLiteral.__set_value(*origin_value);
561
        (*node).__set_bool_literal(boolLiteral);
562
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN));
563
    } else if constexpr (T == TYPE_TINYINT) {
564
        const auto* origin_value = reinterpret_cast<const int8_t*>(data);
565
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
566
        TIntLiteral intLiteral;
567
        intLiteral.__set_value(*origin_value);
568
        (*node).__set_int_literal(intLiteral);
569
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT));
570
    } else if constexpr (T == TYPE_SMALLINT) {
571
        const auto* origin_value = reinterpret_cast<const int16_t*>(data);
572
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
573
        TIntLiteral intLiteral;
574
        intLiteral.__set_value(*origin_value);
575
        (*node).__set_int_literal(intLiteral);
576
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT));
577
    } else if constexpr (T == TYPE_INT) {
578
        const auto* origin_value = reinterpret_cast<const int32_t*>(data);
579
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
580
        TIntLiteral intLiteral;
581
        intLiteral.__set_value(*origin_value);
582
        (*node).__set_int_literal(intLiteral);
583
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT));
584
    } else if constexpr (T == TYPE_BIGINT) {
585
        const auto* origin_value = reinterpret_cast<const int64_t*>(data);
586
        (*node).__set_node_type(TExprNodeType::INT_LITERAL);
587
        TIntLiteral intLiteral;
588
        intLiteral.__set_value(*origin_value);
589
        (*node).__set_int_literal(intLiteral);
590
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT));
591
    } else if constexpr (T == TYPE_LARGEINT) {
592
        const auto* origin_value = reinterpret_cast<const int128_t*>(data);
593
        (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL);
594
        TLargeIntLiteral large_int_literal;
595
        large_int_literal.__set_value(LargeIntValue::to_string(*origin_value));
596
        (*node).__set_large_int_literal(large_int_literal);
597
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT));
598
    } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME)) {
599
        const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data);
600
        TDateLiteral date_literal;
601
        char convert_buffer[30];
602
        origin_value->to_string(convert_buffer);
603
        date_literal.__set_value(convert_buffer);
604
        (*node).__set_date_literal(date_literal);
605
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
606
        if (origin_value->type() == TimeType::TIME_DATE) {
607
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE));
608
        } else if (origin_value->type() == TimeType::TIME_DATETIME) {
609
            (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME));
610
        }
611
    } else if constexpr (T == TYPE_DATEV2) {
612
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data);
613
        TDateLiteral date_literal;
614
        char convert_buffer[30];
615
        origin_value->to_string(convert_buffer);
616
        date_literal.__set_value(convert_buffer);
617
        (*node).__set_date_literal(date_literal);
618
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
619
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2));
620
    } else if constexpr (T == TYPE_DATETIMEV2) {
621
        const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data);
622
        TDateLiteral date_literal;
623
        char convert_buffer[30];
624
        origin_value->to_string(convert_buffer, scale);
625
        date_literal.__set_value(convert_buffer);
626
        (*node).__set_date_literal(date_literal);
627
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
628
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale));
629
77
    } else if constexpr (T == TYPE_TIMESTAMPTZ) {
630
77
        const auto* origin_value = reinterpret_cast<const TimestampTzValue*>(data);
631
77
        TDateLiteral date_literal;
632
77
        auto tz = cctz::utc_time_zone();
633
77
        auto tz_str = origin_value->to_string(tz, scale);
634
77
        date_literal.__set_value(tz_str);
635
77
        (*node).__set_date_literal(date_literal);
636
77
        (*node).__set_node_type(TExprNodeType::DATE_LITERAL);
637
77
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMESTAMPTZ, precision, scale));
638
    } else if constexpr (T == TYPE_DECIMALV2) {
639
        const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data);
640
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
641
        TDecimalLiteral decimal_literal;
642
        decimal_literal.__set_value(origin_value->to_string());
643
        (*node).__set_decimal_literal(decimal_literal);
644
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale));
645
    } else if constexpr (T == TYPE_DECIMAL32) {
646
        const auto* origin_value = reinterpret_cast<const Decimal<int32_t>*>(data);
647
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
648
        TDecimalLiteral decimal_literal;
649
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
650
        (*node).__set_decimal_literal(decimal_literal);
651
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale));
652
    } else if constexpr (T == TYPE_DECIMAL64) {
653
        const auto* origin_value = reinterpret_cast<const Decimal<int64_t>*>(data);
654
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
655
        TDecimalLiteral decimal_literal;
656
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
657
        (*node).__set_decimal_literal(decimal_literal);
658
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale));
659
    } else if constexpr (T == TYPE_DECIMAL128I) {
660
        const auto* origin_value = reinterpret_cast<const Decimal<int128_t>*>(data);
661
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
662
        TDecimalLiteral decimal_literal;
663
        // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF
664
        // on the RF producer side is an int128 value with 38 digits of 9, and this is the
665
        // final min value of the MinMax RF if the fragment instance has no data.
666
        // Need to truncate the value to the right precision and scale here, to avoid
667
        // error when casting string back to decimal later.
668
        // TODO: this is a temporary solution, the best solution is to produce the
669
        // right min max value at the producer side.
670
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
671
        (*node).__set_decimal_literal(decimal_literal);
672
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale));
673
    } else if constexpr (T == TYPE_DECIMAL256) {
674
        const auto* origin_value = reinterpret_cast<const Decimal<wide::Int256>*>(data);
675
        (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL);
676
        TDecimalLiteral decimal_literal;
677
        decimal_literal.__set_value(origin_value->to_string(precision, scale));
678
        (*node).__set_decimal_literal(decimal_literal);
679
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale));
680
    } else if constexpr (T == TYPE_FLOAT) {
681
        const auto* origin_value = reinterpret_cast<const float*>(data);
682
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
683
        TFloatLiteral float_literal;
684
        float_literal.__set_value(*origin_value);
685
        (*node).__set_float_literal(float_literal);
686
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT));
687
    } else if constexpr (T == TYPE_DOUBLE) {
688
        const auto* origin_value = reinterpret_cast<const double*>(data);
689
        (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL);
690
        TFloatLiteral float_literal;
691
        float_literal.__set_value(*origin_value);
692
        (*node).__set_float_literal(float_literal);
693
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE));
694
    } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) {
695
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
696
        (*node).__set_node_type(TExprNodeType::STRING_LITERAL);
697
        TStringLiteral string_literal;
698
        string_literal.__set_value(*origin_value);
699
        (*node).__set_string_literal(string_literal);
700
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING));
701
    } else if constexpr (T == TYPE_IPV4) {
702
        const auto* origin_value = reinterpret_cast<const IPv4*>(data);
703
        (*node).__set_node_type(TExprNodeType::IPV4_LITERAL);
704
        TIPv4Literal literal;
705
        literal.__set_value(*origin_value);
706
        (*node).__set_ipv4_literal(literal);
707
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4));
708
    } else if constexpr (T == TYPE_IPV6) {
709
        const auto* origin_value = reinterpret_cast<const IPv6*>(data);
710
        (*node).__set_node_type(TExprNodeType::IPV6_LITERAL);
711
        TIPv6Literal literal;
712
        literal.__set_value(CastToString::from_ip(*origin_value));
713
        (*node).__set_ipv6_literal(literal);
714
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6));
715
    } else if constexpr (T == TYPE_TIMEV2) {
716
        // Runtime filters preserve TIMEV2's microsecond carrier and scale in the literal node.
717
        const auto* origin_value = reinterpret_cast<const double*>(data);
718
        TTimeV2Literal timev2_literal;
719
        timev2_literal.__set_value(*origin_value);
720
        (*node).__set_timev2_literal(timev2_literal);
721
        (*node).__set_node_type(TExprNodeType::TIMEV2_LITERAL);
722
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2, precision, scale));
723
    } else if constexpr (T == TYPE_VARBINARY) {
724
        const auto* origin_value = reinterpret_cast<const std::string*>(data);
725
        (*node).__set_node_type(TExprNodeType::VARBINARY_LITERAL);
726
        TVarBinaryLiteral varbinary_literal;
727
        varbinary_literal.__set_value(*origin_value);
728
        (*node).__set_varbinary_literal(varbinary_literal);
729
        (*node).__set_type(create_type_desc(PrimitiveType::TYPE_VARBINARY));
730
    } else {
731
        return Status::InvalidArgument("Invalid argument type!");
732
    }
733
77
    return Status::OK();
734
77
}
Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE41EEENS_6StatusEPKvPNS_9TExprNodeEii
735
// NOLINTEND(readability-function-size)
736
737
TExprNode create_texpr_node_from(const void* data, const PrimitiveType& type, int precision = 0,
738
                                 int scale = 0);
739
740
TExprNode create_texpr_node_from(const Field& field, const PrimitiveType& type, int precision,
741
                                 int scale);
742
743
#include "common/compile_check_end.h"
744
} // namespace doris