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