/root/doris/be/src/vec/exprs/vexpr.h
Line | Count | Source (jump to first uncovered line) |
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/status.h" |
34 | | #include "olap/rowset/segment_v2/inverted_index_reader.h" |
35 | | #include "runtime/define_primitive_type.h" |
36 | | #include "runtime/large_int_value.h" |
37 | | #include "runtime/types.h" |
38 | | #include "udf/udf.h" |
39 | | #include "vec/aggregate_functions/aggregate_function.h" |
40 | | #include "vec/columns/column.h" |
41 | | #include "vec/core/block.h" |
42 | | #include "vec/core/column_with_type_and_name.h" |
43 | | #include "vec/core/types.h" |
44 | | #include "vec/core/wide_integer.h" |
45 | | #include "vec/data_types/data_type.h" |
46 | | #include "vec/data_types/data_type_ipv6.h" |
47 | | #include "vec/exprs/vexpr_fwd.h" |
48 | | #include "vec/functions/function.h" |
49 | | |
50 | | namespace doris { |
51 | | class BitmapFilterFuncBase; |
52 | | class BloomFilterFuncBase; |
53 | | class HybridSetBase; |
54 | | class ObjectPool; |
55 | | class RowDescriptor; |
56 | | class RuntimeState; |
57 | | |
58 | | namespace vectorized { |
59 | | #include "common/compile_check_begin.h" |
60 | | |
61 | | #define RETURN_IF_ERROR_OR_PREPARED(stmt) \ |
62 | 12 | if (_prepared) { \ |
63 | 0 | return Status::OK(); \ |
64 | 0 | } \ |
65 | 12 | _prepared = true; \ |
66 | 12 | RETURN_IF_ERROR(stmt); |
67 | | |
68 | | // VExpr should be used as shared pointer because it will be passed between classes |
69 | | // like runtime filter to scan node, or from scannode to scanner. We could not make sure |
70 | | // the relatioinship between threads and classes. |
71 | | class VExpr { |
72 | | public: |
73 | | // resize inserted param column to make sure column size equal to block.rows() and return param column index |
74 | | // keep return type same with block::columns() |
75 | 14 | static uint32_t insert_param(Block* block, ColumnWithTypeAndName&& elem, size_t size) { |
76 | | // usually elem.column always is const column, so we just clone it. |
77 | 14 | elem.column = elem.column->clone_resized(size); |
78 | 14 | block->insert(std::move(elem)); |
79 | | // just inserted. so no need to check underflow. |
80 | 14 | return block->columns() - 1; |
81 | 14 | } |
82 | | |
83 | | static bool is_acting_on_a_slot(const VExpr& expr); |
84 | | |
85 | | VExpr(const TExprNode& node); |
86 | | VExpr(const VExpr& vexpr); |
87 | | VExpr(TypeDescriptor type, bool is_slotref, bool is_nullable); |
88 | | // only used for test |
89 | 9 | VExpr() = default; |
90 | 35 | virtual ~VExpr() = default; |
91 | | |
92 | | virtual const std::string& expr_name() const = 0; |
93 | 0 | virtual std::string expr_label() { return ""; } |
94 | | |
95 | | /// Initializes this expr instance for execution. This does not include initializing |
96 | | /// state in the VExprContext; 'context' should only be used to register a |
97 | | /// FunctionContext via RegisterFunctionContext(). |
98 | | /// |
99 | | /// Subclasses overriding this function should call VExpr::Prepare() to recursively call |
100 | | /// Prepare() on the expr tree |
101 | | /// row_desc used in vslot_ref and some subclass to specify column |
102 | | virtual Status prepare(RuntimeState* state, const RowDescriptor& row_desc, |
103 | | VExprContext* context); |
104 | | |
105 | | /// Initializes 'context' for execution. If scope if FRAGMENT_LOCAL, both fragment- and |
106 | | /// thread-local state should be initialized. Otherwise, if scope is THREAD_LOCAL, only |
107 | | /// thread-local state should be initialized. |
108 | | // |
109 | | /// Subclasses overriding this function should call VExpr::Open() to recursively call |
110 | | /// Open() on the expr tree |
111 | | virtual Status open(RuntimeState* state, VExprContext* context, |
112 | | FunctionContext::FunctionStateScope scope); |
113 | | |
114 | | // before execute, check if expr has been parepared+opened. |
115 | 0 | [[maybe_unused]] Status ready_status() const { |
116 | 0 | if (_prepare_finished && _open_finished) { |
117 | 0 | return Status::OK(); |
118 | 0 | } |
119 | 0 | return Status::InternalError(expr_name() + " is not ready when execute"); |
120 | 0 | } |
121 | | |
122 | | virtual Status execute(VExprContext* context, Block* block, int* result_column_id) = 0; |
123 | | |
124 | | // execute current expr with inverted index to filter block. Given a roaring bitmap of match rows |
125 | 0 | virtual Status evaluate_inverted_index(VExprContext* context, uint32_t segment_num_rows) { |
126 | 0 | return Status::OK(); |
127 | 0 | } |
128 | | |
129 | | Status _evaluate_inverted_index(VExprContext* context, const FunctionBasePtr& function, |
130 | | uint32_t segment_num_rows); |
131 | | |
132 | | // Only the 4th parameter is used in the runtime filter. In and MinMax need overwrite the |
133 | | // interface |
134 | | virtual Status execute_runtime_fitler(VExprContext* context, Block* block, |
135 | 0 | int* result_column_id, ColumnNumbers& args) { |
136 | 0 | return execute(context, block, result_column_id); |
137 | 0 | }; |
138 | | |
139 | | /// Subclasses overriding this function should call VExpr::Close(). |
140 | | // |
141 | | /// If scope if FRAGMENT_LOCAL, both fragment- and thread-local state should be torn |
142 | | /// down. Otherwise, if scope is THREAD_LOCAL, only thread-local state should be torn |
143 | | /// down. |
144 | | virtual void close(VExprContext* context, FunctionContext::FunctionStateScope scope); |
145 | | |
146 | 14 | DataTypePtr& data_type() { return _data_type; } |
147 | | |
148 | 18 | TypeDescriptor type() { return _type; } |
149 | | |
150 | 0 | bool is_slot_ref() const { return _node_type == TExprNodeType::SLOT_REF; } |
151 | 0 | virtual bool is_literal() const { return false; } |
152 | | |
153 | 0 | TExprNodeType::type node_type() const { return _node_type; } |
154 | | |
155 | 0 | TExprOpcode::type op() const { return _opcode; } |
156 | | |
157 | 7 | void add_child(const VExprSPtr& expr) { _children.push_back(expr); } |
158 | 0 | VExprSPtr get_child(uint16_t i) const { return _children[i]; } |
159 | | // Expr's children number is restricted by org.apache.doris.common.Config#expr_children_limit, 10000 default. and strongly not recommend to change. |
160 | | // There's little to worry about it. uint16 is enough. |
161 | 0 | uint16_t get_num_children() const { return static_cast<uint16_t>(_children.size()); } |
162 | | |
163 | 0 | virtual bool is_rf_wrapper() const { |
164 | 0 | return std::ranges::any_of(_children.begin(), _children.end(), |
165 | 0 | [](VExprSPtr child) { return child->is_rf_wrapper(); }); |
166 | 0 | } |
167 | | |
168 | 0 | virtual void do_judge_selectivity(uint64_t filter_rows, uint64_t input_rows) { |
169 | 0 | for (auto child : _children) { |
170 | 0 | child->do_judge_selectivity(filter_rows, input_rows); |
171 | 0 | } |
172 | 0 | } |
173 | | |
174 | | static Status create_expr_tree(const TExpr& texpr, VExprContextSPtr& ctx); |
175 | | |
176 | | static Status create_expr_trees(const std::vector<TExpr>& texprs, VExprContextSPtrs& ctxs); |
177 | | |
178 | | static Status prepare(const VExprContextSPtrs& ctxs, RuntimeState* state, |
179 | | const RowDescriptor& row_desc); |
180 | | |
181 | | static Status open(const VExprContextSPtrs& ctxs, RuntimeState* state); |
182 | | |
183 | | static Status clone_if_not_exists(const VExprContextSPtrs& ctxs, RuntimeState* state, |
184 | | VExprContextSPtrs& new_ctxs); |
185 | | |
186 | 0 | bool is_nullable() const { return _data_type->is_nullable(); } |
187 | | |
188 | 0 | PrimitiveType result_type() const { return _type.type; } |
189 | | |
190 | | static Status create_expr(const TExprNode& expr_node, VExprSPtr& expr); |
191 | | |
192 | | static Status create_tree_from_thrift(const std::vector<TExprNode>& nodes, int* node_idx, |
193 | | VExprSPtr& root_expr, VExprContextSPtr& ctx); |
194 | | |
195 | | static Status check_expr_output_type(const VExprContextSPtrs& ctxs, |
196 | | const RowDescriptor& output_row_desc); |
197 | 23 | virtual const VExprSPtrs& children() const { return _children; } |
198 | 0 | void set_children(const VExprSPtrs& children) { _children = children; } |
199 | 0 | void set_children(VExprSPtrs&& children) { _children = std::move(children); } |
200 | | virtual std::string debug_string() const; |
201 | | static std::string debug_string(const VExprSPtrs& exprs); |
202 | | static std::string debug_string(const VExprContextSPtrs& ctxs); |
203 | | |
204 | 0 | void set_getting_const_col(bool val = true) { _getting_const_col = val; } |
205 | | |
206 | 0 | bool is_and_expr() const { return _fn.name.function_name == "and"; } |
207 | | |
208 | 0 | virtual bool is_compound_predicate() const { return false; } |
209 | | |
210 | 0 | const TFunction& fn() const { return _fn; } |
211 | | |
212 | | /// Returns true if expr doesn't contain slotrefs, i.e., can be evaluated |
213 | | /// with get_value(NULL). The default implementation returns true if all of |
214 | | /// the children are constant. |
215 | | virtual bool is_constant() const; |
216 | | |
217 | | /// If this expr is constant, evaluates the expr with no input row argument and returns |
218 | | /// the output. Returns nullptr if the argument is not constant. The returned ColumnPtr is |
219 | | /// owned by this expr. This should only be called after Open() has been called on this |
220 | | /// expr. |
221 | | Status get_const_col(VExprContext* context, std::shared_ptr<ColumnPtrWrapper>* column_wrapper); |
222 | | |
223 | 0 | int fn_context_index() const { return _fn_context_index; } |
224 | | |
225 | 0 | static VExprSPtr expr_without_cast(const VExprSPtr& expr) { |
226 | 0 | if (expr->node_type() == TExprNodeType::CAST_EXPR) { |
227 | 0 | return expr_without_cast(expr->_children[0]); |
228 | 0 | } |
229 | 0 | return expr; |
230 | 0 | } |
231 | | |
232 | | // If this expr is a RuntimeFilterWrapper, this method will return an underlying rf expression |
233 | 0 | virtual VExprSPtr get_impl() const { return {}; } |
234 | | |
235 | | // If this expr is a BloomPredicate, this method will return a BloomFilterFunc |
236 | 0 | virtual std::shared_ptr<BloomFilterFuncBase> get_bloom_filter_func() const { |
237 | 0 | LOG(FATAL) << "Method 'get_bloom_filter_func()' is not supported in expression: " |
238 | 0 | << this->debug_string(); |
239 | 0 | return nullptr; |
240 | 0 | } |
241 | | |
242 | 0 | virtual std::shared_ptr<HybridSetBase> get_set_func() const { return nullptr; } |
243 | | |
244 | | // If this expr is a BitmapPredicate, this method will return a BitmapFilterFunc |
245 | 0 | virtual std::shared_ptr<BitmapFilterFuncBase> get_bitmap_filter_func() const { |
246 | 0 | LOG(FATAL) << "Method 'get_bitmap_filter_func()' is not supported in expression: " |
247 | 0 | << this->debug_string(); |
248 | 0 | return nullptr; |
249 | 0 | } |
250 | | |
251 | | // fast_execute can direct copy expr filter result which build by apply index in segment_iterator |
252 | | bool fast_execute(doris::vectorized::VExprContext* context, doris::vectorized::Block* block, |
253 | | int* result_column_id); |
254 | | |
255 | 0 | virtual bool can_push_down_to_index() const { return false; } |
256 | | virtual bool equals(const VExpr& other); |
257 | 0 | void set_index_unique_id(uint32_t index_unique_id) { _index_unique_id = index_unique_id; } |
258 | 0 | uint32_t index_unique_id() const { return _index_unique_id; } |
259 | | |
260 | | protected: |
261 | | /// Simple debug string that provides no expr subclass-specific information |
262 | 0 | std::string debug_string(const std::string& expr_name) const { |
263 | 0 | std::stringstream out; |
264 | 0 | out << expr_name << "(" << VExpr::debug_string() << ")"; |
265 | 0 | return out.str(); |
266 | 0 | } |
267 | | |
268 | 2 | std::string get_child_names() { |
269 | 2 | std::string res; |
270 | 2 | for (auto child : _children) { |
271 | 2 | if (!res.empty()) { |
272 | 0 | res += ", "; |
273 | 0 | } |
274 | 2 | res += child->expr_name(); |
275 | 2 | } |
276 | 2 | return res; |
277 | 2 | } |
278 | | |
279 | 0 | bool is_const_and_have_executed() { return (is_constant() && (_constant_col != nullptr)); } |
280 | | |
281 | | Status get_result_from_const(vectorized::Block* block, const std::string& expr_name, |
282 | | int* result_column_id); |
283 | | |
284 | | Status check_constant(const Block& block, ColumnNumbers arguments) const; |
285 | | |
286 | | /// Helper function that calls ctx->register(), sets fn_context_index_, and returns the |
287 | | /// registered FunctionContext |
288 | | void register_function_context(RuntimeState* state, VExprContext* context); |
289 | | |
290 | | /// Helper function to initialize function context, called in `open` phase of VExpr: |
291 | | /// 1. Set constant columns result of function arguments. |
292 | | /// 2. Call function's prepare() to initialize function state, fragment-local or |
293 | | /// thread-local according the input `FunctionStateScope` argument. |
294 | | Status init_function_context(RuntimeState* state, VExprContext* context, |
295 | | FunctionContext::FunctionStateScope scope, |
296 | | const FunctionBasePtr& function) const; |
297 | | |
298 | | /// Helper function to close function context, fragment-local or thread-local according |
299 | | /// the input `FunctionStateScope` argument. Called in `close` phase of VExpr. |
300 | | void close_function_context(VExprContext* context, FunctionContext::FunctionStateScope scope, |
301 | | const FunctionBasePtr& function) const; |
302 | | |
303 | | TExprNodeType::type _node_type; |
304 | | // Used to check what opcode |
305 | | TExprOpcode::type _opcode; |
306 | | TypeDescriptor _type; |
307 | | DataTypePtr _data_type; |
308 | | VExprSPtrs _children; // in few hundreds |
309 | | TFunction _fn; |
310 | | |
311 | | /// Index to pass to ExprContext::fn_context() to retrieve this expr's FunctionContext. |
312 | | /// Set in RegisterFunctionContext(). -1 if this expr does not need a FunctionContext and |
313 | | /// doesn't call RegisterFunctionContext(). |
314 | | int _fn_context_index = -1; |
315 | | |
316 | | // If this expr is constant, this will store and cache the value generated by |
317 | | // get_const_col() |
318 | | std::shared_ptr<ColumnPtrWrapper> _constant_col; |
319 | | bool _prepared = false; // for base class VExpr |
320 | | bool _getting_const_col = |
321 | | false; // if true, current execute() is in prepare() (that is, can't check _prepared) |
322 | | // for concrete classes |
323 | | bool _prepare_finished = false; |
324 | | bool _open_finished = false; |
325 | | |
326 | | // ensuring uniqueness during index traversal |
327 | | uint32_t _index_unique_id = 0; |
328 | | bool _can_fast_execute = false; |
329 | | bool _enable_inverted_index_query = true; |
330 | | }; |
331 | | |
332 | | } // namespace vectorized |
333 | | |
334 | | // NOLINTBEGIN(readability-function-size) |
335 | | template <PrimitiveType T> |
336 | | Status create_texpr_literal_node(const void* data, TExprNode* node, int precision = 0, |
337 | 0 | int scale = 0) { |
338 | 0 | if constexpr (T == TYPE_BOOLEAN) { |
339 | 0 | const auto* origin_value = reinterpret_cast<const bool*>(data); |
340 | 0 | TBoolLiteral boolLiteral; |
341 | 0 | (*node).__set_node_type(TExprNodeType::BOOL_LITERAL); |
342 | 0 | boolLiteral.__set_value(*origin_value); |
343 | 0 | (*node).__set_bool_literal(boolLiteral); |
344 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BOOLEAN)); |
345 | 0 | } else if constexpr (T == TYPE_TINYINT) { |
346 | 0 | const auto* origin_value = reinterpret_cast<const int8_t*>(data); |
347 | 0 | (*node).__set_node_type(TExprNodeType::INT_LITERAL); |
348 | 0 | TIntLiteral intLiteral; |
349 | 0 | intLiteral.__set_value(*origin_value); |
350 | 0 | (*node).__set_int_literal(intLiteral); |
351 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TINYINT)); |
352 | 0 | } else if constexpr (T == TYPE_SMALLINT) { |
353 | 0 | const auto* origin_value = reinterpret_cast<const int16_t*>(data); |
354 | 0 | (*node).__set_node_type(TExprNodeType::INT_LITERAL); |
355 | 0 | TIntLiteral intLiteral; |
356 | 0 | intLiteral.__set_value(*origin_value); |
357 | 0 | (*node).__set_int_literal(intLiteral); |
358 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_SMALLINT)); |
359 | 0 | } else if constexpr (T == TYPE_INT) { |
360 | 0 | const auto* origin_value = reinterpret_cast<const int32_t*>(data); |
361 | 0 | (*node).__set_node_type(TExprNodeType::INT_LITERAL); |
362 | 0 | TIntLiteral intLiteral; |
363 | 0 | intLiteral.__set_value(*origin_value); |
364 | 0 | (*node).__set_int_literal(intLiteral); |
365 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_INT)); |
366 | 0 | } else if constexpr (T == TYPE_BIGINT) { |
367 | 0 | const auto* origin_value = reinterpret_cast<const int64_t*>(data); |
368 | 0 | (*node).__set_node_type(TExprNodeType::INT_LITERAL); |
369 | 0 | TIntLiteral intLiteral; |
370 | 0 | intLiteral.__set_value(*origin_value); |
371 | 0 | (*node).__set_int_literal(intLiteral); |
372 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_BIGINT)); |
373 | 0 | } else if constexpr (T == TYPE_LARGEINT) { |
374 | 0 | const auto* origin_value = reinterpret_cast<const int128_t*>(data); |
375 | 0 | (*node).__set_node_type(TExprNodeType::LARGE_INT_LITERAL); |
376 | 0 | TLargeIntLiteral large_int_literal; |
377 | 0 | large_int_literal.__set_value(LargeIntValue::to_string(*origin_value)); |
378 | 0 | (*node).__set_large_int_literal(large_int_literal); |
379 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_LARGEINT)); |
380 | 0 | } else if constexpr ((T == TYPE_DATE) || (T == TYPE_DATETIME) || (T == TYPE_TIMEV2)) { |
381 | 0 | const auto* origin_value = reinterpret_cast<const VecDateTimeValue*>(data); |
382 | 0 | TDateLiteral date_literal; |
383 | 0 | char convert_buffer[30]; |
384 | 0 | origin_value->to_string(convert_buffer); |
385 | 0 | date_literal.__set_value(convert_buffer); |
386 | 0 | (*node).__set_date_literal(date_literal); |
387 | 0 | (*node).__set_node_type(TExprNodeType::DATE_LITERAL); |
388 | 0 | if (origin_value->type() == TimeType::TIME_DATE) { |
389 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATE)); |
390 | 0 | } else if (origin_value->type() == TimeType::TIME_DATETIME) { |
391 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIME)); |
392 | 0 | } else if (origin_value->type() == TimeType::TIME_TIME) { |
393 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_TIMEV2)); |
394 | 0 | } |
395 | 0 | } else if constexpr (T == TYPE_DATEV2) { |
396 | 0 | const auto* origin_value = reinterpret_cast<const DateV2Value<DateV2ValueType>*>(data); |
397 | 0 | TDateLiteral date_literal; |
398 | 0 | char convert_buffer[30]; |
399 | 0 | origin_value->to_string(convert_buffer); |
400 | 0 | date_literal.__set_value(convert_buffer); |
401 | 0 | (*node).__set_date_literal(date_literal); |
402 | 0 | (*node).__set_node_type(TExprNodeType::DATE_LITERAL); |
403 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATEV2)); |
404 | 0 | } else if constexpr (T == TYPE_DATETIMEV2) { |
405 | 0 | const auto* origin_value = reinterpret_cast<const DateV2Value<DateTimeV2ValueType>*>(data); |
406 | 0 | TDateLiteral date_literal; |
407 | 0 | char convert_buffer[30]; |
408 | 0 | origin_value->to_string(convert_buffer, scale); |
409 | 0 | date_literal.__set_value(convert_buffer); |
410 | 0 | (*node).__set_date_literal(date_literal); |
411 | 0 | (*node).__set_node_type(TExprNodeType::DATE_LITERAL); |
412 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DATETIMEV2, precision, scale)); |
413 | 0 | } else if constexpr (T == TYPE_DECIMALV2) { |
414 | 0 | const auto* origin_value = reinterpret_cast<const DecimalV2Value*>(data); |
415 | 0 | (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL); |
416 | 0 | TDecimalLiteral decimal_literal; |
417 | 0 | decimal_literal.__set_value(origin_value->to_string()); |
418 | 0 | (*node).__set_decimal_literal(decimal_literal); |
419 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMALV2, precision, scale)); |
420 | 0 | } else if constexpr (T == TYPE_DECIMAL32) { |
421 | 0 | const auto* origin_value = reinterpret_cast<const vectorized::Decimal<int32_t>*>(data); |
422 | 0 | (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL); |
423 | 0 | TDecimalLiteral decimal_literal; |
424 | 0 | decimal_literal.__set_value(origin_value->to_string(precision, scale)); |
425 | 0 | (*node).__set_decimal_literal(decimal_literal); |
426 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL32, precision, scale)); |
427 | 0 | } else if constexpr (T == TYPE_DECIMAL64) { |
428 | 0 | const auto* origin_value = reinterpret_cast<const vectorized::Decimal<int64_t>*>(data); |
429 | 0 | (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL); |
430 | 0 | TDecimalLiteral decimal_literal; |
431 | 0 | decimal_literal.__set_value(origin_value->to_string(precision, scale)); |
432 | 0 | (*node).__set_decimal_literal(decimal_literal); |
433 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL64, precision, scale)); |
434 | 0 | } else if constexpr (T == TYPE_DECIMAL128I) { |
435 | 0 | const auto* origin_value = reinterpret_cast<const vectorized::Decimal<int128_t>*>(data); |
436 | 0 | (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL); |
437 | 0 | TDecimalLiteral decimal_literal; |
438 | | // e.g. For a decimal(26,6) column, the initial value of the _min of the MinMax RF |
439 | | // on the RF producer side is an int128 value with 38 digits of 9, and this is the |
440 | | // final min value of the MinMax RF if the fragment instance has no data. |
441 | | // Need to truncate the value to the right precision and scale here, to avoid |
442 | | // error when casting string back to decimal later. |
443 | | // TODO: this is a temporary solution, the best solution is to produce the |
444 | | // right min max value at the producer side. |
445 | 0 | decimal_literal.__set_value(origin_value->to_string(precision, scale)); |
446 | 0 | (*node).__set_decimal_literal(decimal_literal); |
447 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL128I, precision, scale)); |
448 | 0 | } else if constexpr (T == TYPE_DECIMAL256) { |
449 | 0 | const auto* origin_value = reinterpret_cast<const vectorized::Decimal<wide::Int256>*>(data); |
450 | 0 | (*node).__set_node_type(TExprNodeType::DECIMAL_LITERAL); |
451 | 0 | TDecimalLiteral decimal_literal; |
452 | 0 | decimal_literal.__set_value(origin_value->to_string(precision, scale)); |
453 | 0 | (*node).__set_decimal_literal(decimal_literal); |
454 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DECIMAL256, precision, scale)); |
455 | 0 | } else if constexpr (T == TYPE_FLOAT) { |
456 | 0 | const auto* origin_value = reinterpret_cast<const float*>(data); |
457 | 0 | (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL); |
458 | 0 | TFloatLiteral float_literal; |
459 | 0 | float_literal.__set_value(*origin_value); |
460 | 0 | (*node).__set_float_literal(float_literal); |
461 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_FLOAT)); |
462 | 0 | } else if constexpr (T == TYPE_DOUBLE) { |
463 | 0 | const auto* origin_value = reinterpret_cast<const double*>(data); |
464 | 0 | (*node).__set_node_type(TExprNodeType::FLOAT_LITERAL); |
465 | 0 | TFloatLiteral float_literal; |
466 | 0 | float_literal.__set_value(*origin_value); |
467 | 0 | (*node).__set_float_literal(float_literal); |
468 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_DOUBLE)); |
469 | 0 | } else if constexpr ((T == TYPE_STRING) || (T == TYPE_CHAR) || (T == TYPE_VARCHAR)) { |
470 | 0 | const auto* origin_value = reinterpret_cast<const std::string*>(data); |
471 | 0 | (*node).__set_node_type(TExprNodeType::STRING_LITERAL); |
472 | 0 | TStringLiteral string_literal; |
473 | 0 | string_literal.__set_value(*origin_value); |
474 | 0 | (*node).__set_string_literal(string_literal); |
475 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_STRING)); |
476 | 0 | } else if constexpr (T == TYPE_IPV4) { |
477 | 0 | const auto* origin_value = reinterpret_cast<const IPv4*>(data); |
478 | 0 | (*node).__set_node_type(TExprNodeType::IPV4_LITERAL); |
479 | 0 | TIPv4Literal literal; |
480 | 0 | literal.__set_value(*origin_value); |
481 | 0 | (*node).__set_ipv4_literal(literal); |
482 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV4)); |
483 | 0 | } else if constexpr (T == TYPE_IPV6) { |
484 | 0 | const auto* origin_value = reinterpret_cast<const IPv6*>(data); |
485 | 0 | (*node).__set_node_type(TExprNodeType::IPV6_LITERAL); |
486 | 0 | TIPv6Literal literal; |
487 | 0 | literal.__set_value(vectorized::DataTypeIPv6::to_string(*origin_value)); |
488 | 0 | (*node).__set_ipv6_literal(literal); |
489 | 0 | (*node).__set_type(create_type_desc(PrimitiveType::TYPE_IPV6)); |
490 | 0 | } else { |
491 | 0 | return Status::InvalidArgument("Invalid argument type!"); |
492 | 0 | } |
493 | 0 | return Status::OK(); |
494 | 0 | } Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE2EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE3EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE4EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE5EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE6EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE7EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE8EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE9EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE25EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE26EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE11EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE12EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE20EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE28EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE29EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE30EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE35EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE15EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE10EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE23EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE36EEENS_6StatusEPKvPNS_9TExprNodeEii Unexecuted instantiation: _ZN5doris25create_texpr_literal_nodeILNS_13PrimitiveTypeE37EEENS_6StatusEPKvPNS_9TExprNodeEii |
495 | | // NOLINTEND(readability-function-size) |
496 | | |
497 | | TExprNode create_texpr_node_from(const void* data, const PrimitiveType& type, int precision = 0, |
498 | | int scale = 0); |
499 | | |
500 | | #include "common/compile_check_end.h" |
501 | | } // namespace doris |