/root/doris/be/src/vec/exprs/vliteral.cpp
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 | | #include "vec/exprs/vliteral.h" |
19 | | |
20 | | #include <fmt/format.h> |
21 | | #include <gen_cpp/Exprs_types.h> |
22 | | #include <gen_cpp/Types_types.h> |
23 | | #include <glog/logging.h> |
24 | | #include <math.h> |
25 | | #include <stdint.h> |
26 | | #include <sys/types.h> |
27 | | |
28 | | #include <algorithm> |
29 | | #include <ostream> |
30 | | #include <vector> |
31 | | |
32 | | #include "common/exception.h" |
33 | | #include "olap/olap_common.h" |
34 | | #include "runtime/decimalv2_value.h" |
35 | | #include "runtime/define_primitive_type.h" |
36 | | #include "runtime/jsonb_value.h" |
37 | | #include "runtime/large_int_value.h" |
38 | | #include "runtime/types.h" |
39 | | #include "util/string_parser.hpp" |
40 | | #include "vec/aggregate_functions/aggregate_function.h" |
41 | | #include "vec/columns/column.h" |
42 | | #include "vec/common/string_ref.h" |
43 | | #include "vec/common/typeid_cast.h" |
44 | | #include "vec/core/block.h" |
45 | | #include "vec/core/field.h" |
46 | | #include "vec/core/types.h" |
47 | | #include "vec/data_types/data_type_decimal.h" |
48 | | #include "vec/runtime/vdatetime_value.h" |
49 | | |
50 | | namespace doris::vectorized { |
51 | | class VExprContext; |
52 | | |
53 | 14 | void VLiteral::init(const TExprNode& node) { |
54 | 14 | Field field; |
55 | 14 | field = _data_type->get_field(node); |
56 | 14 | _column_ptr = _data_type->create_column_const(1, field); |
57 | 14 | } |
58 | | |
59 | 0 | Status VLiteral::prepare(RuntimeState* state, const RowDescriptor& desc, VExprContext* context) { |
60 | 0 | RETURN_IF_ERROR_OR_PREPARED(VExpr::prepare(state, desc, context)); |
61 | 0 | return Status::OK(); |
62 | 0 | } |
63 | | |
64 | | Status VLiteral::open(RuntimeState* state, VExprContext* context, |
65 | 0 | FunctionContext::FunctionStateScope scope) { |
66 | 0 | RETURN_IF_ERROR(VExpr::open(state, context, scope)); |
67 | 0 | return Status::OK(); |
68 | 0 | } |
69 | | |
70 | 14 | Status VLiteral::execute(VExprContext* context, vectorized::Block* block, int* result_column_id) { |
71 | | // Literal expr should return least one row. |
72 | | // sometimes we just use a VLiteral without open or prepare. so can't check it at this moment |
73 | 14 | size_t row_size = std::max(block->rows(), _column_ptr->size()); |
74 | 14 | *result_column_id = VExpr::insert_param(block, {_column_ptr, _data_type, _expr_name}, row_size); |
75 | 14 | return Status::OK(); |
76 | 14 | } |
77 | | |
78 | 14 | std::string VLiteral::value() const { |
79 | 14 | DCHECK(_column_ptr->size() == 1); |
80 | 14 | return _data_type->to_string(*_column_ptr, 0); |
81 | 14 | } |
82 | | |
83 | 0 | std::string VLiteral::debug_string() const { |
84 | 0 | std::stringstream out; |
85 | 0 | out << "VLiteral (name = " << _expr_name; |
86 | 0 | out << ", type = " << _data_type->get_name(); |
87 | 0 | out << ", value = (" << value(); |
88 | 0 | out << "))"; |
89 | 0 | return out.str(); |
90 | 0 | } |
91 | | |
92 | 0 | bool VLiteral::equals(const VExpr& other) { |
93 | 0 | const auto* other_ptr = dynamic_cast<const VLiteral*>(&other); |
94 | 0 | if (!other_ptr) { |
95 | 0 | return false; |
96 | 0 | } |
97 | 0 | if (this->_expr_name != other_ptr->_expr_name) { |
98 | 0 | return false; |
99 | 0 | } |
100 | 0 | if (this->_column_ptr->structure_equals(*other_ptr->_column_ptr)) { |
101 | 0 | if (this->_column_ptr->size() != other_ptr->_column_ptr->size()) { |
102 | 0 | return false; |
103 | 0 | } |
104 | 0 | for (size_t i = 0; i < this->_column_ptr->size(); i++) { |
105 | 0 | if (this->_column_ptr->compare_at(i, i, *other_ptr->_column_ptr, -1) != 0) { |
106 | 0 | return false; |
107 | 0 | } |
108 | 0 | } |
109 | 0 | } |
110 | 0 | return true; |
111 | 0 | } |
112 | | |
113 | | } // namespace doris::vectorized |