/root/doris/be/src/olap/delete_handler.cpp
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 | | #include "olap/delete_handler.h" |
19 | | |
20 | | #include <gen_cpp/PaloInternalService_types.h> |
21 | | #include <gen_cpp/olap_file.pb.h> |
22 | | #include <thrift/protocol/TDebugProtocol.h> |
23 | | |
24 | | #include <string> |
25 | | #include <vector> |
26 | | |
27 | | #include "common/config.h" |
28 | | #include "common/logging.h" |
29 | | #include "common/status.h" |
30 | | #include "olap/block_column_predicate.h" |
31 | | #include "olap/olap_common.h" |
32 | | #include "olap/predicate_creator.h" |
33 | | #include "olap/tablet_schema.h" |
34 | | #include "olap/utils.h" |
35 | | #include "util/debug_points.h" |
36 | | #include "vec/functions/cast/cast_parameters.h" |
37 | | #include "vec/functions/cast/cast_to_boolean.h" |
38 | | #include "vec/functions/cast/cast_to_date_or_datetime_impl.hpp" |
39 | | #include "vec/functions/cast/cast_to_datetimev2_impl.hpp" |
40 | | #include "vec/functions/cast/cast_to_datev2_impl.hpp" |
41 | | #include "vec/functions/cast/cast_to_decimal.h" |
42 | | #include "vec/functions/cast/cast_to_float.h" |
43 | | #include "vec/functions/cast/cast_to_int.h" |
44 | | #include "vec/functions/cast/cast_to_ip.h" |
45 | | |
46 | | using apache::thrift::ThriftDebugString; |
47 | | using std::vector; |
48 | | using std::string; |
49 | | |
50 | | using ::google::protobuf::RepeatedPtrField; |
51 | | |
52 | | namespace doris { |
53 | | |
54 | | template <PrimitiveType PType> |
55 | | Status convert(const vectorized::DataTypePtr& data_type, const std::string& str, |
56 | 149 | vectorized::Arena& arena, typename PrimitiveTypeTraits<PType>::CppType& res) { |
57 | | if constexpr (PType == TYPE_TINYINT || PType == TYPE_SMALLINT || PType == TYPE_INT || |
58 | 92 | PType == TYPE_BIGINT || PType == TYPE_LARGEINT) { |
59 | 92 | vectorized::CastParameters parameters; |
60 | 92 | if (!vectorized::CastToInt::from_string({str.data(), str.size()}, res, parameters)) { |
61 | 2 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
62 | 2 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
63 | 2 | str); |
64 | 2 | } |
65 | 90 | return Status::OK(); |
66 | 92 | } |
67 | 0 | if constexpr (PType == TYPE_FLOAT || PType == TYPE_DOUBLE) { |
68 | 0 | vectorized::CastParameters parameters; |
69 | 0 | if (!vectorized::CastToFloat::from_string({str.data(), str.size()}, res, parameters)) { |
70 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
71 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
72 | 0 | str); |
73 | 0 | } |
74 | 0 | return Status::OK(); |
75 | 0 | } |
76 | 0 | if constexpr (PType == TYPE_DATE) { |
77 | 0 | vectorized::CastParameters parameters; |
78 | 0 | if (!vectorized::CastToDateOrDatetime::from_string<false>({str.data(), str.size()}, res, |
79 | 0 | nullptr, parameters)) { |
80 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
81 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
82 | 0 | str); |
83 | 0 | } |
84 | 0 | return Status::OK(); |
85 | 0 | } |
86 | 0 | if constexpr (PType == TYPE_DATETIME) { |
87 | 0 | vectorized::CastParameters parameters; |
88 | 0 | if (!vectorized::CastToDateOrDatetime::from_string<true>({str.data(), str.size()}, res, |
89 | 0 | nullptr, parameters)) { |
90 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
91 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
92 | 0 | str); |
93 | 0 | } |
94 | 0 | return Status::OK(); |
95 | 0 | } |
96 | 0 | if constexpr (PType == TYPE_DATEV2) { |
97 | 0 | vectorized::CastParameters parameters; |
98 | 0 | if (!vectorized::CastToDateV2::from_string({str.data(), str.size()}, res, nullptr, |
99 | 0 | parameters)) { |
100 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
101 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
102 | 0 | str); |
103 | 0 | } |
104 | 0 | return Status::OK(); |
105 | 0 | } |
106 | 0 | if constexpr (PType == TYPE_DATETIMEV2) { |
107 | 0 | vectorized::CastParameters parameters; |
108 | 0 | if (!vectorized::CastToDatetimeV2::from_string({str.data(), str.size()}, res, nullptr, |
109 | 0 | data_type->get_scale(), parameters)) { |
110 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
111 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
112 | 0 | str); |
113 | 0 | } |
114 | 0 | return Status::OK(); |
115 | 0 | } |
116 | 18 | if constexpr (PType == TYPE_TIMESTAMPTZ) { |
117 | 18 | vectorized::CastParameters parameters; |
118 | 18 | if (!vectorized::CastToTimstampTz::from_string({str.data(), str.size()}, res, parameters, |
119 | 18 | nullptr, data_type->get_scale())) { |
120 | 5 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
121 | 5 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
122 | 5 | str); |
123 | 5 | } |
124 | 13 | return Status::OK(); |
125 | 18 | } |
126 | 0 | if constexpr (PType == TYPE_CHAR) { |
127 | 0 | size_t target = assert_cast<const vectorized::DataTypeString*>( |
128 | 0 | vectorized::remove_nullable(data_type).get()) |
129 | 0 | ->len(); |
130 | 0 | res = {str.data(), str.size()}; |
131 | 0 | if (target > str.size()) { |
132 | 0 | char* buffer = arena.alloc(target); |
133 | 0 | memset(buffer, 0, target); |
134 | 0 | memcpy(buffer, str.data(), str.size()); |
135 | 0 | res = {buffer, target}; |
136 | 0 | } |
137 | 0 | return Status::OK(); |
138 | 0 | } |
139 | 38 | if constexpr (PType == TYPE_STRING || PType == TYPE_VARCHAR) { |
140 | 38 | char* buffer = arena.alloc(str.size()); |
141 | 38 | memcpy(buffer, str.data(), str.size()); |
142 | 38 | res = {buffer, str.size()}; |
143 | 38 | return Status::OK(); |
144 | 38 | } |
145 | 0 | if constexpr (PType == TYPE_BOOLEAN) { |
146 | 0 | vectorized::CastParameters parameters; |
147 | 0 | vectorized::UInt8 tmp; |
148 | 0 | if (!vectorized::CastToBool::from_string({str.data(), str.size()}, tmp, parameters)) { |
149 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
150 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
151 | 0 | str); |
152 | 0 | } |
153 | 0 | res = tmp != 0; |
154 | 0 | return Status::OK(); |
155 | 0 | } |
156 | 1 | if constexpr (PType == TYPE_IPV4) { |
157 | 1 | vectorized::CastParameters parameters; |
158 | 1 | if (!vectorized::CastToIPv4::from_string({str.data(), str.size()}, res, parameters)) { |
159 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
160 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
161 | 0 | str); |
162 | 0 | } |
163 | 1 | return Status::OK(); |
164 | 1 | } |
165 | 0 | if constexpr (PType == TYPE_IPV6) { |
166 | 0 | vectorized::CastParameters parameters; |
167 | 0 | if (!vectorized::CastToIPv6::from_string({str.data(), str.size()}, res, parameters)) { |
168 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
169 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
170 | 0 | str); |
171 | 0 | } |
172 | 0 | return Status::OK(); |
173 | 0 | } |
174 | 0 | if constexpr (PType == TYPE_DECIMALV2) { |
175 | 0 | vectorized::CastParameters parameters; |
176 | 0 | vectorized::Decimal128V2 tmp; |
177 | 0 | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, tmp, |
178 | 0 | data_type->get_precision(), |
179 | 0 | data_type->get_scale(), parameters)) { |
180 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
181 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
182 | 0 | str); |
183 | 0 | } |
184 | 0 | res = DecimalV2Value(tmp.value); |
185 | 0 | return Status::OK(); |
186 | 0 | } else if constexpr (is_decimal(PType)) { |
187 | 0 | vectorized::CastParameters parameters; |
188 | 0 | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, res, |
189 | 0 | data_type->get_precision(), |
190 | 0 | data_type->get_scale(), parameters)) { |
191 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
192 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), |
193 | 0 | str); |
194 | 0 | } |
195 | 0 | return Status::OK(); |
196 | 0 | } |
197 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
198 | 149 | "unsupported data type in delete handler. type={}", |
199 | 149 | type_to_string(data_type->get_primitive_type())); |
200 | 149 | } _ZN5doris7convertILNS_13PrimitiveTypeE3EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Line | Count | Source | 56 | 9 | vectorized::Arena& arena, typename PrimitiveTypeTraits<PType>::CppType& res) { | 57 | | if constexpr (PType == TYPE_TINYINT || PType == TYPE_SMALLINT || PType == TYPE_INT || | 58 | 9 | PType == TYPE_BIGINT || PType == TYPE_LARGEINT) { | 59 | 9 | vectorized::CastParameters parameters; | 60 | 9 | if (!vectorized::CastToInt::from_string({str.data(), str.size()}, res, parameters)) { | 61 | 2 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 62 | 2 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 63 | 2 | str); | 64 | 2 | } | 65 | 7 | return Status::OK(); | 66 | 9 | } | 67 | | if constexpr (PType == TYPE_FLOAT || PType == TYPE_DOUBLE) { | 68 | | vectorized::CastParameters parameters; | 69 | | if (!vectorized::CastToFloat::from_string({str.data(), str.size()}, res, parameters)) { | 70 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 71 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 72 | | str); | 73 | | } | 74 | | return Status::OK(); | 75 | | } | 76 | | if constexpr (PType == TYPE_DATE) { | 77 | | vectorized::CastParameters parameters; | 78 | | if (!vectorized::CastToDateOrDatetime::from_string<false>({str.data(), str.size()}, res, | 79 | | nullptr, parameters)) { | 80 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 81 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 82 | | str); | 83 | | } | 84 | | return Status::OK(); | 85 | | } | 86 | | if constexpr (PType == TYPE_DATETIME) { | 87 | | vectorized::CastParameters parameters; | 88 | | if (!vectorized::CastToDateOrDatetime::from_string<true>({str.data(), str.size()}, res, | 89 | | nullptr, parameters)) { | 90 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 91 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 92 | | str); | 93 | | } | 94 | | return Status::OK(); | 95 | | } | 96 | | if constexpr (PType == TYPE_DATEV2) { | 97 | | vectorized::CastParameters parameters; | 98 | | if (!vectorized::CastToDateV2::from_string({str.data(), str.size()}, res, nullptr, | 99 | | parameters)) { | 100 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 101 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 102 | | str); | 103 | | } | 104 | | return Status::OK(); | 105 | | } | 106 | | if constexpr (PType == TYPE_DATETIMEV2) { | 107 | | vectorized::CastParameters parameters; | 108 | | if (!vectorized::CastToDatetimeV2::from_string({str.data(), str.size()}, res, nullptr, | 109 | | data_type->get_scale(), parameters)) { | 110 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 111 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 112 | | str); | 113 | | } | 114 | | return Status::OK(); | 115 | | } | 116 | | if constexpr (PType == TYPE_TIMESTAMPTZ) { | 117 | | vectorized::CastParameters parameters; | 118 | | if (!vectorized::CastToTimstampTz::from_string({str.data(), str.size()}, res, parameters, | 119 | | nullptr, data_type->get_scale())) { | 120 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 121 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 122 | | str); | 123 | | } | 124 | | return Status::OK(); | 125 | | } | 126 | | if constexpr (PType == TYPE_CHAR) { | 127 | | size_t target = assert_cast<const vectorized::DataTypeString*>( | 128 | | vectorized::remove_nullable(data_type).get()) | 129 | | ->len(); | 130 | | res = {str.data(), str.size()}; | 131 | | if (target > str.size()) { | 132 | | char* buffer = arena.alloc(target); | 133 | | memset(buffer, 0, target); | 134 | | memcpy(buffer, str.data(), str.size()); | 135 | | res = {buffer, target}; | 136 | | } | 137 | | return Status::OK(); | 138 | | } | 139 | | if constexpr (PType == TYPE_STRING || PType == TYPE_VARCHAR) { | 140 | | char* buffer = arena.alloc(str.size()); | 141 | | memcpy(buffer, str.data(), str.size()); | 142 | | res = {buffer, str.size()}; | 143 | | return Status::OK(); | 144 | | } | 145 | | if constexpr (PType == TYPE_BOOLEAN) { | 146 | | vectorized::CastParameters parameters; | 147 | | vectorized::UInt8 tmp; | 148 | | if (!vectorized::CastToBool::from_string({str.data(), str.size()}, tmp, parameters)) { | 149 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 150 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 151 | | str); | 152 | | } | 153 | | res = tmp != 0; | 154 | | return Status::OK(); | 155 | | } | 156 | | if constexpr (PType == TYPE_IPV4) { | 157 | | vectorized::CastParameters parameters; | 158 | | if (!vectorized::CastToIPv4::from_string({str.data(), str.size()}, res, parameters)) { | 159 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 160 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 161 | | str); | 162 | | } | 163 | | return Status::OK(); | 164 | | } | 165 | | if constexpr (PType == TYPE_IPV6) { | 166 | | vectorized::CastParameters parameters; | 167 | | if (!vectorized::CastToIPv6::from_string({str.data(), str.size()}, res, parameters)) { | 168 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 169 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 170 | | str); | 171 | | } | 172 | | return Status::OK(); | 173 | | } | 174 | | if constexpr (PType == TYPE_DECIMALV2) { | 175 | | vectorized::CastParameters parameters; | 176 | | vectorized::Decimal128V2 tmp; | 177 | | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, tmp, | 178 | | data_type->get_precision(), | 179 | | data_type->get_scale(), parameters)) { | 180 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 181 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 182 | | str); | 183 | | } | 184 | | res = DecimalV2Value(tmp.value); | 185 | | return Status::OK(); | 186 | 9 | } else if constexpr (is_decimal(PType)) { | 187 | 9 | vectorized::CastParameters parameters; | 188 | 9 | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, res, | 189 | 9 | data_type->get_precision(), | 190 | 9 | data_type->get_scale(), parameters)) { | 191 | 9 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 192 | 9 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 193 | 9 | str); | 194 | 9 | } | 195 | 9 | return Status::OK(); | 196 | 9 | } | 197 | 9 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 198 | 9 | "unsupported data type in delete handler. type={}", | 199 | 9 | type_to_string(data_type->get_primitive_type())); | 200 | 9 | } |
_ZN5doris7convertILNS_13PrimitiveTypeE4EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Line | Count | Source | 56 | 8 | vectorized::Arena& arena, typename PrimitiveTypeTraits<PType>::CppType& res) { | 57 | | if constexpr (PType == TYPE_TINYINT || PType == TYPE_SMALLINT || PType == TYPE_INT || | 58 | 8 | PType == TYPE_BIGINT || PType == TYPE_LARGEINT) { | 59 | 8 | vectorized::CastParameters parameters; | 60 | 8 | if (!vectorized::CastToInt::from_string({str.data(), str.size()}, res, parameters)) { | 61 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 62 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 63 | 0 | str); | 64 | 0 | } | 65 | 8 | return Status::OK(); | 66 | 8 | } | 67 | | if constexpr (PType == TYPE_FLOAT || PType == TYPE_DOUBLE) { | 68 | | vectorized::CastParameters parameters; | 69 | | if (!vectorized::CastToFloat::from_string({str.data(), str.size()}, res, parameters)) { | 70 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 71 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 72 | | str); | 73 | | } | 74 | | return Status::OK(); | 75 | | } | 76 | | if constexpr (PType == TYPE_DATE) { | 77 | | vectorized::CastParameters parameters; | 78 | | if (!vectorized::CastToDateOrDatetime::from_string<false>({str.data(), str.size()}, res, | 79 | | nullptr, parameters)) { | 80 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 81 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 82 | | str); | 83 | | } | 84 | | return Status::OK(); | 85 | | } | 86 | | if constexpr (PType == TYPE_DATETIME) { | 87 | | vectorized::CastParameters parameters; | 88 | | if (!vectorized::CastToDateOrDatetime::from_string<true>({str.data(), str.size()}, res, | 89 | | nullptr, parameters)) { | 90 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 91 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 92 | | str); | 93 | | } | 94 | | return Status::OK(); | 95 | | } | 96 | | if constexpr (PType == TYPE_DATEV2) { | 97 | | vectorized::CastParameters parameters; | 98 | | if (!vectorized::CastToDateV2::from_string({str.data(), str.size()}, res, nullptr, | 99 | | parameters)) { | 100 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 101 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 102 | | str); | 103 | | } | 104 | | return Status::OK(); | 105 | | } | 106 | | if constexpr (PType == TYPE_DATETIMEV2) { | 107 | | vectorized::CastParameters parameters; | 108 | | if (!vectorized::CastToDatetimeV2::from_string({str.data(), str.size()}, res, nullptr, | 109 | | data_type->get_scale(), parameters)) { | 110 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 111 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 112 | | str); | 113 | | } | 114 | | return Status::OK(); | 115 | | } | 116 | | if constexpr (PType == TYPE_TIMESTAMPTZ) { | 117 | | vectorized::CastParameters parameters; | 118 | | if (!vectorized::CastToTimstampTz::from_string({str.data(), str.size()}, res, parameters, | 119 | | nullptr, data_type->get_scale())) { | 120 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 121 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 122 | | str); | 123 | | } | 124 | | return Status::OK(); | 125 | | } | 126 | | if constexpr (PType == TYPE_CHAR) { | 127 | | size_t target = assert_cast<const vectorized::DataTypeString*>( | 128 | | vectorized::remove_nullable(data_type).get()) | 129 | | ->len(); | 130 | | res = {str.data(), str.size()}; | 131 | | if (target > str.size()) { | 132 | | char* buffer = arena.alloc(target); | 133 | | memset(buffer, 0, target); | 134 | | memcpy(buffer, str.data(), str.size()); | 135 | | res = {buffer, target}; | 136 | | } | 137 | | return Status::OK(); | 138 | | } | 139 | | if constexpr (PType == TYPE_STRING || PType == TYPE_VARCHAR) { | 140 | | char* buffer = arena.alloc(str.size()); | 141 | | memcpy(buffer, str.data(), str.size()); | 142 | | res = {buffer, str.size()}; | 143 | | return Status::OK(); | 144 | | } | 145 | | if constexpr (PType == TYPE_BOOLEAN) { | 146 | | vectorized::CastParameters parameters; | 147 | | vectorized::UInt8 tmp; | 148 | | if (!vectorized::CastToBool::from_string({str.data(), str.size()}, tmp, parameters)) { | 149 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 150 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 151 | | str); | 152 | | } | 153 | | res = tmp != 0; | 154 | | return Status::OK(); | 155 | | } | 156 | | if constexpr (PType == TYPE_IPV4) { | 157 | | vectorized::CastParameters parameters; | 158 | | if (!vectorized::CastToIPv4::from_string({str.data(), str.size()}, res, parameters)) { | 159 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 160 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 161 | | str); | 162 | | } | 163 | | return Status::OK(); | 164 | | } | 165 | | if constexpr (PType == TYPE_IPV6) { | 166 | | vectorized::CastParameters parameters; | 167 | | if (!vectorized::CastToIPv6::from_string({str.data(), str.size()}, res, parameters)) { | 168 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 169 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 170 | | str); | 171 | | } | 172 | | return Status::OK(); | 173 | | } | 174 | | if constexpr (PType == TYPE_DECIMALV2) { | 175 | | vectorized::CastParameters parameters; | 176 | | vectorized::Decimal128V2 tmp; | 177 | | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, tmp, | 178 | | data_type->get_precision(), | 179 | | data_type->get_scale(), parameters)) { | 180 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 181 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 182 | | str); | 183 | | } | 184 | | res = DecimalV2Value(tmp.value); | 185 | | return Status::OK(); | 186 | 8 | } else if constexpr (is_decimal(PType)) { | 187 | 8 | vectorized::CastParameters parameters; | 188 | 8 | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, res, | 189 | 8 | data_type->get_precision(), | 190 | 8 | data_type->get_scale(), parameters)) { | 191 | 8 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 192 | 8 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 193 | 8 | str); | 194 | 8 | } | 195 | 8 | return Status::OK(); | 196 | 8 | } | 197 | 8 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 198 | 8 | "unsupported data type in delete handler. type={}", | 199 | 8 | type_to_string(data_type->get_primitive_type())); | 200 | 8 | } |
_ZN5doris7convertILNS_13PrimitiveTypeE5EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Line | Count | Source | 56 | 75 | vectorized::Arena& arena, typename PrimitiveTypeTraits<PType>::CppType& res) { | 57 | | if constexpr (PType == TYPE_TINYINT || PType == TYPE_SMALLINT || PType == TYPE_INT || | 58 | 75 | PType == TYPE_BIGINT || PType == TYPE_LARGEINT) { | 59 | 75 | vectorized::CastParameters parameters; | 60 | 75 | if (!vectorized::CastToInt::from_string({str.data(), str.size()}, res, parameters)) { | 61 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 62 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 63 | 0 | str); | 64 | 0 | } | 65 | 75 | return Status::OK(); | 66 | 75 | } | 67 | | if constexpr (PType == TYPE_FLOAT || PType == TYPE_DOUBLE) { | 68 | | vectorized::CastParameters parameters; | 69 | | if (!vectorized::CastToFloat::from_string({str.data(), str.size()}, res, parameters)) { | 70 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 71 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 72 | | str); | 73 | | } | 74 | | return Status::OK(); | 75 | | } | 76 | | if constexpr (PType == TYPE_DATE) { | 77 | | vectorized::CastParameters parameters; | 78 | | if (!vectorized::CastToDateOrDatetime::from_string<false>({str.data(), str.size()}, res, | 79 | | nullptr, parameters)) { | 80 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 81 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 82 | | str); | 83 | | } | 84 | | return Status::OK(); | 85 | | } | 86 | | if constexpr (PType == TYPE_DATETIME) { | 87 | | vectorized::CastParameters parameters; | 88 | | if (!vectorized::CastToDateOrDatetime::from_string<true>({str.data(), str.size()}, res, | 89 | | nullptr, parameters)) { | 90 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 91 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 92 | | str); | 93 | | } | 94 | | return Status::OK(); | 95 | | } | 96 | | if constexpr (PType == TYPE_DATEV2) { | 97 | | vectorized::CastParameters parameters; | 98 | | if (!vectorized::CastToDateV2::from_string({str.data(), str.size()}, res, nullptr, | 99 | | parameters)) { | 100 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 101 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 102 | | str); | 103 | | } | 104 | | return Status::OK(); | 105 | | } | 106 | | if constexpr (PType == TYPE_DATETIMEV2) { | 107 | | vectorized::CastParameters parameters; | 108 | | if (!vectorized::CastToDatetimeV2::from_string({str.data(), str.size()}, res, nullptr, | 109 | | data_type->get_scale(), parameters)) { | 110 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 111 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 112 | | str); | 113 | | } | 114 | | return Status::OK(); | 115 | | } | 116 | | if constexpr (PType == TYPE_TIMESTAMPTZ) { | 117 | | vectorized::CastParameters parameters; | 118 | | if (!vectorized::CastToTimstampTz::from_string({str.data(), str.size()}, res, parameters, | 119 | | nullptr, data_type->get_scale())) { | 120 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 121 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 122 | | str); | 123 | | } | 124 | | return Status::OK(); | 125 | | } | 126 | | if constexpr (PType == TYPE_CHAR) { | 127 | | size_t target = assert_cast<const vectorized::DataTypeString*>( | 128 | | vectorized::remove_nullable(data_type).get()) | 129 | | ->len(); | 130 | | res = {str.data(), str.size()}; | 131 | | if (target > str.size()) { | 132 | | char* buffer = arena.alloc(target); | 133 | | memset(buffer, 0, target); | 134 | | memcpy(buffer, str.data(), str.size()); | 135 | | res = {buffer, target}; | 136 | | } | 137 | | return Status::OK(); | 138 | | } | 139 | | if constexpr (PType == TYPE_STRING || PType == TYPE_VARCHAR) { | 140 | | char* buffer = arena.alloc(str.size()); | 141 | | memcpy(buffer, str.data(), str.size()); | 142 | | res = {buffer, str.size()}; | 143 | | return Status::OK(); | 144 | | } | 145 | | if constexpr (PType == TYPE_BOOLEAN) { | 146 | | vectorized::CastParameters parameters; | 147 | | vectorized::UInt8 tmp; | 148 | | if (!vectorized::CastToBool::from_string({str.data(), str.size()}, tmp, parameters)) { | 149 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 150 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 151 | | str); | 152 | | } | 153 | | res = tmp != 0; | 154 | | return Status::OK(); | 155 | | } | 156 | | if constexpr (PType == TYPE_IPV4) { | 157 | | vectorized::CastParameters parameters; | 158 | | if (!vectorized::CastToIPv4::from_string({str.data(), str.size()}, res, parameters)) { | 159 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 160 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 161 | | str); | 162 | | } | 163 | | return Status::OK(); | 164 | | } | 165 | | if constexpr (PType == TYPE_IPV6) { | 166 | | vectorized::CastParameters parameters; | 167 | | if (!vectorized::CastToIPv6::from_string({str.data(), str.size()}, res, parameters)) { | 168 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 169 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 170 | | str); | 171 | | } | 172 | | return Status::OK(); | 173 | | } | 174 | | if constexpr (PType == TYPE_DECIMALV2) { | 175 | | vectorized::CastParameters parameters; | 176 | | vectorized::Decimal128V2 tmp; | 177 | | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, tmp, | 178 | | data_type->get_precision(), | 179 | | data_type->get_scale(), parameters)) { | 180 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 181 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 182 | | str); | 183 | | } | 184 | | res = DecimalV2Value(tmp.value); | 185 | | return Status::OK(); | 186 | 75 | } else if constexpr (is_decimal(PType)) { | 187 | 75 | vectorized::CastParameters parameters; | 188 | 75 | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, res, | 189 | 75 | data_type->get_precision(), | 190 | 75 | data_type->get_scale(), parameters)) { | 191 | 75 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 192 | 75 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 193 | 75 | str); | 194 | 75 | } | 195 | 75 | return Status::OK(); | 196 | 75 | } | 197 | 75 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 198 | 75 | "unsupported data type in delete handler. type={}", | 199 | 75 | type_to_string(data_type->get_primitive_type())); | 200 | 75 | } |
Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE6EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE7EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE8EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE9EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE11EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE12EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE25EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE26EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE _ZN5doris7convertILNS_13PrimitiveTypeE42EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Line | Count | Source | 56 | 18 | vectorized::Arena& arena, typename PrimitiveTypeTraits<PType>::CppType& res) { | 57 | | if constexpr (PType == TYPE_TINYINT || PType == TYPE_SMALLINT || PType == TYPE_INT || | 58 | | PType == TYPE_BIGINT || PType == TYPE_LARGEINT) { | 59 | | vectorized::CastParameters parameters; | 60 | | if (!vectorized::CastToInt::from_string({str.data(), str.size()}, res, parameters)) { | 61 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 62 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 63 | | str); | 64 | | } | 65 | | return Status::OK(); | 66 | | } | 67 | | if constexpr (PType == TYPE_FLOAT || PType == TYPE_DOUBLE) { | 68 | | vectorized::CastParameters parameters; | 69 | | if (!vectorized::CastToFloat::from_string({str.data(), str.size()}, res, parameters)) { | 70 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 71 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 72 | | str); | 73 | | } | 74 | | return Status::OK(); | 75 | | } | 76 | | if constexpr (PType == TYPE_DATE) { | 77 | | vectorized::CastParameters parameters; | 78 | | if (!vectorized::CastToDateOrDatetime::from_string<false>({str.data(), str.size()}, res, | 79 | | nullptr, parameters)) { | 80 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 81 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 82 | | str); | 83 | | } | 84 | | return Status::OK(); | 85 | | } | 86 | | if constexpr (PType == TYPE_DATETIME) { | 87 | | vectorized::CastParameters parameters; | 88 | | if (!vectorized::CastToDateOrDatetime::from_string<true>({str.data(), str.size()}, res, | 89 | | nullptr, parameters)) { | 90 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 91 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 92 | | str); | 93 | | } | 94 | | return Status::OK(); | 95 | | } | 96 | | if constexpr (PType == TYPE_DATEV2) { | 97 | | vectorized::CastParameters parameters; | 98 | | if (!vectorized::CastToDateV2::from_string({str.data(), str.size()}, res, nullptr, | 99 | | parameters)) { | 100 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 101 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 102 | | str); | 103 | | } | 104 | | return Status::OK(); | 105 | | } | 106 | | if constexpr (PType == TYPE_DATETIMEV2) { | 107 | | vectorized::CastParameters parameters; | 108 | | if (!vectorized::CastToDatetimeV2::from_string({str.data(), str.size()}, res, nullptr, | 109 | | data_type->get_scale(), parameters)) { | 110 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 111 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 112 | | str); | 113 | | } | 114 | | return Status::OK(); | 115 | | } | 116 | 18 | if constexpr (PType == TYPE_TIMESTAMPTZ) { | 117 | 18 | vectorized::CastParameters parameters; | 118 | 18 | if (!vectorized::CastToTimstampTz::from_string({str.data(), str.size()}, res, parameters, | 119 | 18 | nullptr, data_type->get_scale())) { | 120 | 5 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 121 | 5 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 122 | 5 | str); | 123 | 5 | } | 124 | 13 | return Status::OK(); | 125 | 18 | } | 126 | | if constexpr (PType == TYPE_CHAR) { | 127 | | size_t target = assert_cast<const vectorized::DataTypeString*>( | 128 | | vectorized::remove_nullable(data_type).get()) | 129 | | ->len(); | 130 | | res = {str.data(), str.size()}; | 131 | | if (target > str.size()) { | 132 | | char* buffer = arena.alloc(target); | 133 | | memset(buffer, 0, target); | 134 | | memcpy(buffer, str.data(), str.size()); | 135 | | res = {buffer, target}; | 136 | | } | 137 | | return Status::OK(); | 138 | | } | 139 | | if constexpr (PType == TYPE_STRING || PType == TYPE_VARCHAR) { | 140 | | char* buffer = arena.alloc(str.size()); | 141 | | memcpy(buffer, str.data(), str.size()); | 142 | | res = {buffer, str.size()}; | 143 | | return Status::OK(); | 144 | | } | 145 | | if constexpr (PType == TYPE_BOOLEAN) { | 146 | | vectorized::CastParameters parameters; | 147 | | vectorized::UInt8 tmp; | 148 | | if (!vectorized::CastToBool::from_string({str.data(), str.size()}, tmp, parameters)) { | 149 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 150 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 151 | | str); | 152 | | } | 153 | | res = tmp != 0; | 154 | | return Status::OK(); | 155 | | } | 156 | | if constexpr (PType == TYPE_IPV4) { | 157 | | vectorized::CastParameters parameters; | 158 | | if (!vectorized::CastToIPv4::from_string({str.data(), str.size()}, res, parameters)) { | 159 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 160 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 161 | | str); | 162 | | } | 163 | | return Status::OK(); | 164 | | } | 165 | | if constexpr (PType == TYPE_IPV6) { | 166 | | vectorized::CastParameters parameters; | 167 | | if (!vectorized::CastToIPv6::from_string({str.data(), str.size()}, res, parameters)) { | 168 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 169 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 170 | | str); | 171 | | } | 172 | | return Status::OK(); | 173 | | } | 174 | | if constexpr (PType == TYPE_DECIMALV2) { | 175 | | vectorized::CastParameters parameters; | 176 | | vectorized::Decimal128V2 tmp; | 177 | | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, tmp, | 178 | | data_type->get_precision(), | 179 | | data_type->get_scale(), parameters)) { | 180 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 181 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 182 | | str); | 183 | | } | 184 | | res = DecimalV2Value(tmp.value); | 185 | | return Status::OK(); | 186 | 18 | } else if constexpr (is_decimal(PType)) { | 187 | 18 | vectorized::CastParameters parameters; | 188 | 18 | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, res, | 189 | 18 | data_type->get_precision(), | 190 | 18 | data_type->get_scale(), parameters)) { | 191 | 18 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 192 | 18 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 193 | 18 | str); | 194 | 18 | } | 195 | 18 | return Status::OK(); | 196 | 18 | } | 197 | 18 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 198 | 18 | "unsupported data type in delete handler. type={}", | 199 | 18 | type_to_string(data_type->get_primitive_type())); | 200 | 18 | } |
Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE2EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE _ZN5doris7convertILNS_13PrimitiveTypeE36EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Line | Count | Source | 56 | 1 | vectorized::Arena& arena, typename PrimitiveTypeTraits<PType>::CppType& res) { | 57 | | if constexpr (PType == TYPE_TINYINT || PType == TYPE_SMALLINT || PType == TYPE_INT || | 58 | | PType == TYPE_BIGINT || PType == TYPE_LARGEINT) { | 59 | | vectorized::CastParameters parameters; | 60 | | if (!vectorized::CastToInt::from_string({str.data(), str.size()}, res, parameters)) { | 61 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 62 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 63 | | str); | 64 | | } | 65 | | return Status::OK(); | 66 | | } | 67 | | if constexpr (PType == TYPE_FLOAT || PType == TYPE_DOUBLE) { | 68 | | vectorized::CastParameters parameters; | 69 | | if (!vectorized::CastToFloat::from_string({str.data(), str.size()}, res, parameters)) { | 70 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 71 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 72 | | str); | 73 | | } | 74 | | return Status::OK(); | 75 | | } | 76 | | if constexpr (PType == TYPE_DATE) { | 77 | | vectorized::CastParameters parameters; | 78 | | if (!vectorized::CastToDateOrDatetime::from_string<false>({str.data(), str.size()}, res, | 79 | | nullptr, parameters)) { | 80 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 81 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 82 | | str); | 83 | | } | 84 | | return Status::OK(); | 85 | | } | 86 | | if constexpr (PType == TYPE_DATETIME) { | 87 | | vectorized::CastParameters parameters; | 88 | | if (!vectorized::CastToDateOrDatetime::from_string<true>({str.data(), str.size()}, res, | 89 | | nullptr, parameters)) { | 90 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 91 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 92 | | str); | 93 | | } | 94 | | return Status::OK(); | 95 | | } | 96 | | if constexpr (PType == TYPE_DATEV2) { | 97 | | vectorized::CastParameters parameters; | 98 | | if (!vectorized::CastToDateV2::from_string({str.data(), str.size()}, res, nullptr, | 99 | | parameters)) { | 100 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 101 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 102 | | str); | 103 | | } | 104 | | return Status::OK(); | 105 | | } | 106 | | if constexpr (PType == TYPE_DATETIMEV2) { | 107 | | vectorized::CastParameters parameters; | 108 | | if (!vectorized::CastToDatetimeV2::from_string({str.data(), str.size()}, res, nullptr, | 109 | | data_type->get_scale(), parameters)) { | 110 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 111 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 112 | | str); | 113 | | } | 114 | | return Status::OK(); | 115 | | } | 116 | | if constexpr (PType == TYPE_TIMESTAMPTZ) { | 117 | | vectorized::CastParameters parameters; | 118 | | if (!vectorized::CastToTimstampTz::from_string({str.data(), str.size()}, res, parameters, | 119 | | nullptr, data_type->get_scale())) { | 120 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 121 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 122 | | str); | 123 | | } | 124 | | return Status::OK(); | 125 | | } | 126 | | if constexpr (PType == TYPE_CHAR) { | 127 | | size_t target = assert_cast<const vectorized::DataTypeString*>( | 128 | | vectorized::remove_nullable(data_type).get()) | 129 | | ->len(); | 130 | | res = {str.data(), str.size()}; | 131 | | if (target > str.size()) { | 132 | | char* buffer = arena.alloc(target); | 133 | | memset(buffer, 0, target); | 134 | | memcpy(buffer, str.data(), str.size()); | 135 | | res = {buffer, target}; | 136 | | } | 137 | | return Status::OK(); | 138 | | } | 139 | | if constexpr (PType == TYPE_STRING || PType == TYPE_VARCHAR) { | 140 | | char* buffer = arena.alloc(str.size()); | 141 | | memcpy(buffer, str.data(), str.size()); | 142 | | res = {buffer, str.size()}; | 143 | | return Status::OK(); | 144 | | } | 145 | | if constexpr (PType == TYPE_BOOLEAN) { | 146 | | vectorized::CastParameters parameters; | 147 | | vectorized::UInt8 tmp; | 148 | | if (!vectorized::CastToBool::from_string({str.data(), str.size()}, tmp, parameters)) { | 149 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 150 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 151 | | str); | 152 | | } | 153 | | res = tmp != 0; | 154 | | return Status::OK(); | 155 | | } | 156 | 1 | if constexpr (PType == TYPE_IPV4) { | 157 | 1 | vectorized::CastParameters parameters; | 158 | 1 | if (!vectorized::CastToIPv4::from_string({str.data(), str.size()}, res, parameters)) { | 159 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 160 | 0 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 161 | 0 | str); | 162 | 0 | } | 163 | 1 | return Status::OK(); | 164 | 1 | } | 165 | | if constexpr (PType == TYPE_IPV6) { | 166 | | vectorized::CastParameters parameters; | 167 | | if (!vectorized::CastToIPv6::from_string({str.data(), str.size()}, res, parameters)) { | 168 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 169 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 170 | | str); | 171 | | } | 172 | | return Status::OK(); | 173 | | } | 174 | | if constexpr (PType == TYPE_DECIMALV2) { | 175 | | vectorized::CastParameters parameters; | 176 | | vectorized::Decimal128V2 tmp; | 177 | | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, tmp, | 178 | | data_type->get_precision(), | 179 | | data_type->get_scale(), parameters)) { | 180 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 181 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 182 | | str); | 183 | | } | 184 | | res = DecimalV2Value(tmp.value); | 185 | | return Status::OK(); | 186 | 1 | } else if constexpr (is_decimal(PType)) { | 187 | 1 | vectorized::CastParameters parameters; | 188 | 1 | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, res, | 189 | 1 | data_type->get_precision(), | 190 | 1 | data_type->get_scale(), parameters)) { | 191 | 1 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 192 | 1 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 193 | 1 | str); | 194 | 1 | } | 195 | 1 | return Status::OK(); | 196 | 1 | } | 197 | 1 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 198 | 1 | "unsupported data type in delete handler. type={}", | 199 | 1 | type_to_string(data_type->get_primitive_type())); | 200 | 1 | } |
Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE37EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE20EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE28EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE29EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE30EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE35EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE15EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Unexecuted instantiation: _ZN5doris7convertILNS_13PrimitiveTypeE10EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE _ZN5doris7convertILNS_13PrimitiveTypeE23EEENS_6StatusERKSt10shared_ptrIKNS_10vectorized9IDataTypeEERKNSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEERNS4_5ArenaERNS_19PrimitiveTypeTraitsIXT_EE7CppTypeE Line | Count | Source | 56 | 38 | vectorized::Arena& arena, typename PrimitiveTypeTraits<PType>::CppType& res) { | 57 | | if constexpr (PType == TYPE_TINYINT || PType == TYPE_SMALLINT || PType == TYPE_INT || | 58 | | PType == TYPE_BIGINT || PType == TYPE_LARGEINT) { | 59 | | vectorized::CastParameters parameters; | 60 | | if (!vectorized::CastToInt::from_string({str.data(), str.size()}, res, parameters)) { | 61 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 62 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 63 | | str); | 64 | | } | 65 | | return Status::OK(); | 66 | | } | 67 | | if constexpr (PType == TYPE_FLOAT || PType == TYPE_DOUBLE) { | 68 | | vectorized::CastParameters parameters; | 69 | | if (!vectorized::CastToFloat::from_string({str.data(), str.size()}, res, parameters)) { | 70 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 71 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 72 | | str); | 73 | | } | 74 | | return Status::OK(); | 75 | | } | 76 | | if constexpr (PType == TYPE_DATE) { | 77 | | vectorized::CastParameters parameters; | 78 | | if (!vectorized::CastToDateOrDatetime::from_string<false>({str.data(), str.size()}, res, | 79 | | nullptr, parameters)) { | 80 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 81 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 82 | | str); | 83 | | } | 84 | | return Status::OK(); | 85 | | } | 86 | | if constexpr (PType == TYPE_DATETIME) { | 87 | | vectorized::CastParameters parameters; | 88 | | if (!vectorized::CastToDateOrDatetime::from_string<true>({str.data(), str.size()}, res, | 89 | | nullptr, parameters)) { | 90 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 91 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 92 | | str); | 93 | | } | 94 | | return Status::OK(); | 95 | | } | 96 | | if constexpr (PType == TYPE_DATEV2) { | 97 | | vectorized::CastParameters parameters; | 98 | | if (!vectorized::CastToDateV2::from_string({str.data(), str.size()}, res, nullptr, | 99 | | parameters)) { | 100 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 101 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 102 | | str); | 103 | | } | 104 | | return Status::OK(); | 105 | | } | 106 | | if constexpr (PType == TYPE_DATETIMEV2) { | 107 | | vectorized::CastParameters parameters; | 108 | | if (!vectorized::CastToDatetimeV2::from_string({str.data(), str.size()}, res, nullptr, | 109 | | data_type->get_scale(), parameters)) { | 110 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 111 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 112 | | str); | 113 | | } | 114 | | return Status::OK(); | 115 | | } | 116 | | if constexpr (PType == TYPE_TIMESTAMPTZ) { | 117 | | vectorized::CastParameters parameters; | 118 | | if (!vectorized::CastToTimstampTz::from_string({str.data(), str.size()}, res, parameters, | 119 | | nullptr, data_type->get_scale())) { | 120 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 121 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 122 | | str); | 123 | | } | 124 | | return Status::OK(); | 125 | | } | 126 | | if constexpr (PType == TYPE_CHAR) { | 127 | | size_t target = assert_cast<const vectorized::DataTypeString*>( | 128 | | vectorized::remove_nullable(data_type).get()) | 129 | | ->len(); | 130 | | res = {str.data(), str.size()}; | 131 | | if (target > str.size()) { | 132 | | char* buffer = arena.alloc(target); | 133 | | memset(buffer, 0, target); | 134 | | memcpy(buffer, str.data(), str.size()); | 135 | | res = {buffer, target}; | 136 | | } | 137 | | return Status::OK(); | 138 | | } | 139 | 38 | if constexpr (PType == TYPE_STRING || PType == TYPE_VARCHAR) { | 140 | 38 | char* buffer = arena.alloc(str.size()); | 141 | 38 | memcpy(buffer, str.data(), str.size()); | 142 | 38 | res = {buffer, str.size()}; | 143 | 38 | return Status::OK(); | 144 | 38 | } | 145 | | if constexpr (PType == TYPE_BOOLEAN) { | 146 | | vectorized::CastParameters parameters; | 147 | | vectorized::UInt8 tmp; | 148 | | if (!vectorized::CastToBool::from_string({str.data(), str.size()}, tmp, parameters)) { | 149 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 150 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 151 | | str); | 152 | | } | 153 | | res = tmp != 0; | 154 | | return Status::OK(); | 155 | | } | 156 | | if constexpr (PType == TYPE_IPV4) { | 157 | | vectorized::CastParameters parameters; | 158 | | if (!vectorized::CastToIPv4::from_string({str.data(), str.size()}, res, parameters)) { | 159 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 160 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 161 | | str); | 162 | | } | 163 | | return Status::OK(); | 164 | | } | 165 | | if constexpr (PType == TYPE_IPV6) { | 166 | | vectorized::CastParameters parameters; | 167 | | if (!vectorized::CastToIPv6::from_string({str.data(), str.size()}, res, parameters)) { | 168 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 169 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 170 | | str); | 171 | | } | 172 | | return Status::OK(); | 173 | | } | 174 | | if constexpr (PType == TYPE_DECIMALV2) { | 175 | | vectorized::CastParameters parameters; | 176 | | vectorized::Decimal128V2 tmp; | 177 | | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, tmp, | 178 | | data_type->get_precision(), | 179 | | data_type->get_scale(), parameters)) { | 180 | | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 181 | | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 182 | | str); | 183 | | } | 184 | | res = DecimalV2Value(tmp.value); | 185 | | return Status::OK(); | 186 | 38 | } else if constexpr (is_decimal(PType)) { | 187 | 38 | vectorized::CastParameters parameters; | 188 | 38 | if (!vectorized::CastToDecimal::from_string({str.data(), str.size()}, res, | 189 | 38 | data_type->get_precision(), | 190 | 38 | data_type->get_scale(), parameters)) { | 191 | 38 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 192 | 38 | "invalid {} string. str={}", type_to_string(data_type->get_primitive_type()), | 193 | 38 | str); | 194 | 38 | } | 195 | 38 | return Status::OK(); | 196 | 38 | } | 197 | 38 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( | 198 | 38 | "unsupported data type in delete handler. type={}", | 199 | 38 | type_to_string(data_type->get_primitive_type())); | 200 | 38 | } |
|
201 | | |
202 | | #define CONVERT_CASE(PType) \ |
203 | 2 | case PType: { \ |
204 | 2 | set = build_set<PType>(); \ |
205 | 5 | for (const auto& s : str) { \ |
206 | 5 | typename PrimitiveTypeTraits<PType>::CppType tmp; \ |
207 | 5 | RETURN_IF_ERROR(convert<PType>(data_type, s, arena, tmp)); \ |
208 | 5 | set->insert(reinterpret_cast<const void*>(&tmp)); \ |
209 | 5 | } \ |
210 | 2 | return Status::OK(); \ |
211 | 2 | } |
212 | | Status convert(const vectorized::DataTypePtr& data_type, const std::list<std::string>& str, |
213 | 2 | vectorized::Arena& arena, std::shared_ptr<HybridSetBase>& set) { |
214 | 2 | switch (data_type->get_primitive_type()) { |
215 | 0 | CONVERT_CASE(TYPE_TINYINT); |
216 | 0 | CONVERT_CASE(TYPE_SMALLINT); |
217 | 0 | CONVERT_CASE(TYPE_INT); |
218 | 0 | CONVERT_CASE(TYPE_BIGINT); |
219 | 0 | CONVERT_CASE(TYPE_LARGEINT); |
220 | 0 | CONVERT_CASE(TYPE_FLOAT); |
221 | 0 | CONVERT_CASE(TYPE_DOUBLE); |
222 | 0 | CONVERT_CASE(TYPE_DATE); |
223 | 0 | CONVERT_CASE(TYPE_DATETIME); |
224 | 0 | CONVERT_CASE(TYPE_DATEV2); |
225 | 0 | CONVERT_CASE(TYPE_DATETIMEV2); |
226 | 2 | CONVERT_CASE(TYPE_TIMESTAMPTZ); |
227 | 0 | CONVERT_CASE(TYPE_BOOLEAN); |
228 | 0 | CONVERT_CASE(TYPE_IPV4); |
229 | 0 | CONVERT_CASE(TYPE_IPV6); |
230 | 0 | CONVERT_CASE(TYPE_DECIMALV2); |
231 | 0 | CONVERT_CASE(TYPE_DECIMAL32); |
232 | 0 | CONVERT_CASE(TYPE_DECIMAL64); |
233 | 0 | CONVERT_CASE(TYPE_DECIMAL128I); |
234 | 0 | CONVERT_CASE(TYPE_DECIMAL256); |
235 | 0 | CONVERT_CASE(TYPE_CHAR); |
236 | 0 | CONVERT_CASE(TYPE_VARCHAR); |
237 | 0 | CONVERT_CASE(TYPE_STRING); |
238 | 0 | default: |
239 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
240 | 0 | "unsupported data type in delete handler. type={}", |
241 | 0 | type_to_string(data_type->get_primitive_type())); |
242 | 2 | } |
243 | 0 | return Status::OK(); |
244 | 2 | } |
245 | | #undef CONVERT_CASE |
246 | | |
247 | | #define CONVERT_CASE(PType) \ |
248 | 106 | case PType: { \ |
249 | 106 | typename PrimitiveTypeTraits<PType>::CppType tmp; \ |
250 | 106 | RETURN_IF_ERROR(convert<PType>(type, res.value_str.front(), arena, tmp)); \ |
251 | 106 | v.data = reinterpret_cast<const char*>(&tmp); \ |
252 | 99 | v.size = sizeof(tmp); \ |
253 | 99 | switch (res.condition_op) { \ |
254 | 10 | case PredicateType::EQ: \ |
255 | 10 | predicate = create_comparison_predicate0<PredicateType::EQ>(index, col_name, type, v, \ |
256 | 10 | true, arena); \ |
257 | 10 | return Status::OK(); \ |
258 | 7 | case PredicateType::NE: \ |
259 | 7 | predicate = create_comparison_predicate0<PredicateType::NE>(index, col_name, type, v, \ |
260 | 7 | true, arena); \ |
261 | 7 | return Status::OK(); \ |
262 | 2 | case PredicateType::GT: \ |
263 | 2 | predicate = create_comparison_predicate0<PredicateType::GT>(index, col_name, type, v, \ |
264 | 2 | true, arena); \ |
265 | 2 | return Status::OK(); \ |
266 | 2 | case PredicateType::GE: \ |
267 | 2 | predicate = create_comparison_predicate0<PredicateType::GE>(index, col_name, type, v, \ |
268 | 2 | true, arena); \ |
269 | 2 | return Status::OK(); \ |
270 | 76 | case PredicateType::LT: \ |
271 | 76 | predicate = create_comparison_predicate0<PredicateType::LT>(index, col_name, type, v, \ |
272 | 76 | true, arena); \ |
273 | 76 | return Status::OK(); \ |
274 | 2 | case PredicateType::LE: \ |
275 | 2 | predicate = create_comparison_predicate0<PredicateType::LE>(index, col_name, type, v, \ |
276 | 2 | true, arena); \ |
277 | 2 | return Status::OK(); \ |
278 | 0 | default: \ |
279 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( \ |
280 | 0 | "invalid condition operator. operator={}", type_to_op_str(res.condition_op)); \ |
281 | 99 | } \ |
282 | 99 | } |
283 | | Status parse_to_predicate(const uint32_t index, const std::string col_name, |
284 | | const vectorized::DataTypePtr& type, |
285 | | DeleteHandler::ConditionParseResult& res, vectorized::Arena& arena, |
286 | 181 | std::shared_ptr<ColumnPredicate>& predicate) { |
287 | 181 | DCHECK_EQ(res.value_str.size(), 1); |
288 | 181 | if (res.condition_op == PredicateType::IS_NULL || |
289 | 181 | res.condition_op == PredicateType::IS_NOT_NULL) { |
290 | 37 | predicate = NullPredicate::create_shared(index, col_name, |
291 | 37 | res.condition_op == PredicateType::IS_NOT_NULL, |
292 | 37 | type->get_primitive_type()); |
293 | 37 | return Status::OK(); |
294 | 37 | } |
295 | 144 | StringRef v; |
296 | 144 | switch (type->get_primitive_type()) { |
297 | 16 | CONVERT_CASE(TYPE_TINYINT); |
298 | 16 | CONVERT_CASE(TYPE_SMALLINT); |
299 | 150 | CONVERT_CASE(TYPE_INT); |
300 | 0 | CONVERT_CASE(TYPE_BIGINT); |
301 | 0 | CONVERT_CASE(TYPE_LARGEINT); |
302 | 0 | CONVERT_CASE(TYPE_FLOAT); |
303 | 0 | CONVERT_CASE(TYPE_DOUBLE); |
304 | 0 | CONVERT_CASE(TYPE_DATE); |
305 | 0 | CONVERT_CASE(TYPE_DATETIME); |
306 | 0 | CONVERT_CASE(TYPE_DATEV2); |
307 | 0 | CONVERT_CASE(TYPE_DATETIMEV2); |
308 | 21 | CONVERT_CASE(TYPE_TIMESTAMPTZ); |
309 | 0 | CONVERT_CASE(TYPE_BOOLEAN); |
310 | 2 | CONVERT_CASE(TYPE_IPV4); |
311 | 0 | CONVERT_CASE(TYPE_IPV6); |
312 | 0 | CONVERT_CASE(TYPE_DECIMALV2); |
313 | 0 | CONVERT_CASE(TYPE_DECIMAL32); |
314 | 0 | CONVERT_CASE(TYPE_DECIMAL64); |
315 | 0 | CONVERT_CASE(TYPE_DECIMAL128I); |
316 | 0 | CONVERT_CASE(TYPE_DECIMAL256); |
317 | 0 | case TYPE_CHAR: |
318 | 0 | case TYPE_VARCHAR: |
319 | 38 | case TYPE_STRING: { |
320 | 38 | RETURN_IF_ERROR(convert<TYPE_STRING>(type, res.value_str.front(), arena, v)); |
321 | 38 | switch (res.condition_op) { |
322 | 38 | case PredicateType::EQ: |
323 | 38 | predicate = create_comparison_predicate0<PredicateType::EQ>(index, col_name, type, v, |
324 | 38 | true, arena); |
325 | 38 | return Status::OK(); |
326 | 0 | case PredicateType::NE: |
327 | 0 | predicate = create_comparison_predicate0<PredicateType::NE>(index, col_name, type, v, |
328 | 0 | true, arena); |
329 | 0 | return Status::OK(); |
330 | 0 | case PredicateType::GT: |
331 | 0 | predicate = create_comparison_predicate0<PredicateType::GT>(index, col_name, type, v, |
332 | 0 | true, arena); |
333 | 0 | return Status::OK(); |
334 | 0 | case PredicateType::GE: |
335 | 0 | predicate = create_comparison_predicate0<PredicateType::GE>(index, col_name, type, v, |
336 | 0 | true, arena); |
337 | 0 | return Status::OK(); |
338 | 0 | case PredicateType::LT: |
339 | 0 | predicate = create_comparison_predicate0<PredicateType::LT>(index, col_name, type, v, |
340 | 0 | true, arena); |
341 | 0 | return Status::OK(); |
342 | 0 | case PredicateType::LE: |
343 | 0 | predicate = create_comparison_predicate0<PredicateType::LE>(index, col_name, type, v, |
344 | 0 | true, arena); |
345 | 0 | return Status::OK(); |
346 | 0 | default: |
347 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
348 | 0 | "invalid condition operator. operator={}", type_to_op_str(res.condition_op)); |
349 | 38 | } |
350 | 0 | break; |
351 | 38 | } |
352 | 0 | default: |
353 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
354 | 0 | "unsupported data type in delete handler. type={}", |
355 | 0 | type_to_string(type->get_primitive_type())); |
356 | 144 | } |
357 | 0 | return Status::OK(); |
358 | 144 | #undef CONVERT_CASE |
359 | 144 | } |
360 | | |
361 | | Status parse_to_in_predicate(const uint32_t index, const std::string& col_name, |
362 | | const vectorized::DataTypePtr& type, |
363 | | DeleteHandler::ConditionParseResult& res, vectorized::Arena& arena, |
364 | 2 | std::shared_ptr<ColumnPredicate>& predicate) { |
365 | 2 | DCHECK_GT(res.value_str.size(), 1); |
366 | 2 | switch (res.condition_op) { |
367 | 1 | case PredicateType::IN_LIST: { |
368 | 1 | std::shared_ptr<HybridSetBase> set; |
369 | 1 | RETURN_IF_ERROR(convert(type, res.value_str, arena, set)); |
370 | 1 | predicate = |
371 | 1 | create_in_list_predicate<PredicateType::IN_LIST>(index, col_name, type, set, true); |
372 | 1 | break; |
373 | 1 | } |
374 | 1 | case PredicateType::NOT_IN_LIST: { |
375 | 1 | std::shared_ptr<HybridSetBase> set; |
376 | 1 | RETURN_IF_ERROR(convert(type, res.value_str, arena, set)); |
377 | 1 | predicate = create_in_list_predicate<PredicateType::NOT_IN_LIST>(index, col_name, type, set, |
378 | 1 | true); |
379 | 1 | break; |
380 | 1 | } |
381 | 0 | default: |
382 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition operator. operator={}", |
383 | 0 | type_to_op_str(res.condition_op)); |
384 | 2 | } |
385 | 2 | return Status::OK(); |
386 | 2 | } |
387 | | |
388 | | // construct sub condition from TCondition |
389 | 101 | std::string construct_sub_predicate(const TCondition& condition) { |
390 | 101 | string op = condition.condition_op; |
391 | 101 | if (op == "<") { |
392 | 50 | op += "<"; |
393 | 51 | } else if (op == ">") { |
394 | 3 | op += ">"; |
395 | 3 | } |
396 | 101 | string condition_str; |
397 | 101 | if ("IS" == op) { |
398 | | // ATTN: tricky! Surround IS with spaces to make it "special" |
399 | 2 | condition_str = condition.column_name + " IS " + condition.condition_values[0]; |
400 | 99 | } else { // multi-elements IN expr has been processed with InPredicatePB |
401 | 99 | if (op == "*=") { |
402 | 2 | op = "="; |
403 | 97 | } else if (op == "!*=") { |
404 | 2 | op = "!="; |
405 | 2 | } |
406 | 99 | condition_str = condition.column_name + op + "'" + condition.condition_values[0] + "'"; |
407 | 99 | } |
408 | 101 | return condition_str; |
409 | 101 | } |
410 | | |
411 | | // make operators from FE adaptive to BE |
412 | 101 | std::string trans_op(const std::string& opt) { |
413 | 101 | std::string op = string(opt); |
414 | 101 | if (op == "<") { |
415 | 50 | op += "<"; |
416 | 51 | } else if (op == ">") { |
417 | 3 | op += ">"; |
418 | 3 | } |
419 | 101 | if ("IS" != op) { |
420 | 99 | if (op == "*=") { |
421 | 2 | op = "="; |
422 | 97 | } else if (op == "!*=") { |
423 | 2 | op = "!="; |
424 | 2 | } |
425 | 99 | } |
426 | 101 | return op; |
427 | 101 | } |
428 | | |
429 | | Status DeleteHandler::generate_delete_predicate(const TabletSchema& schema, |
430 | | const std::vector<TCondition>& conditions, |
431 | 106 | DeletePredicatePB* del_pred) { |
432 | 106 | DBUG_EXECUTE_IF("DeleteHandler::generate_delete_predicate.inject_failure", { |
433 | 106 | return Status::Error<false>(dp->param<int>("error_code"), |
434 | 106 | dp->param<std::string>("error_msg")); |
435 | 106 | }) |
436 | 106 | if (conditions.empty()) { |
437 | 1 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
438 | 1 | "invalid parameters for store_cond. condition_size={}", conditions.size()); |
439 | 1 | } |
440 | | |
441 | | // Check whether the delete condition meets the requirements |
442 | 135 | for (const TCondition& condition : conditions) { |
443 | 135 | RETURN_IF_ERROR(check_condition_valid(schema, condition)); |
444 | 135 | } |
445 | | |
446 | | // Store delete condition |
447 | 105 | for (const TCondition& condition : conditions) { |
448 | 105 | if (condition.condition_values.size() > 1) { |
449 | 4 | InPredicatePB* in_pred = del_pred->add_in_predicates(); |
450 | 4 | if (condition.__isset.column_unique_id) { |
451 | 0 | in_pred->set_column_unique_id(condition.column_unique_id); |
452 | 0 | } |
453 | 4 | in_pred->set_column_name(condition.column_name); |
454 | 4 | bool is_not_in = condition.condition_op == "!*="; |
455 | 4 | in_pred->set_is_not_in(is_not_in); |
456 | 10 | for (const auto& condition_value : condition.condition_values) { |
457 | 10 | in_pred->add_values(condition_value); |
458 | 10 | } |
459 | | |
460 | 4 | LOG(INFO) << "store one sub-delete condition. condition name=" << in_pred->column_name() |
461 | 4 | << "condition size=" << in_pred->values().size(); |
462 | 101 | } else { |
463 | | // write sub predicate v1 for compactbility |
464 | 101 | std::string condition_str = construct_sub_predicate(condition); |
465 | 101 | VLOG_NOTICE << __PRETTY_FUNCTION__ << " condition_str: " << condition_str; |
466 | 101 | del_pred->add_sub_predicates(condition_str); |
467 | 101 | DeleteSubPredicatePB* sub_predicate = del_pred->add_sub_predicates_v2(); |
468 | 101 | if (condition.__isset.column_unique_id) { |
469 | | // only light schema change capable table set this field |
470 | 0 | sub_predicate->set_column_unique_id(condition.column_unique_id); |
471 | 101 | } else { |
472 | 101 | try { |
473 | 101 | [[maybe_unused]] auto parsed_cond = parse_condition(condition_str); |
474 | 101 | } catch (const Exception& e) { |
475 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
476 | 0 | "failed to parse condition_str, condition={}, error={}", |
477 | 0 | ThriftDebugString(condition), e.to_string()); |
478 | 0 | } |
479 | 101 | } |
480 | | |
481 | 101 | sub_predicate->set_column_name(condition.column_name); |
482 | 101 | sub_predicate->set_op(trans_op(condition.condition_op)); |
483 | 101 | sub_predicate->set_cond_value(condition.condition_values[0]); |
484 | 101 | LOG(INFO) << "store one sub-delete condition. condition=" |
485 | 101 | << fmt::format(" {} {} {}", condition.column_name, condition.condition_op, |
486 | 101 | condition.condition_values[0]); |
487 | 101 | } |
488 | 105 | } |
489 | 75 | del_pred->set_version(-1); |
490 | | |
491 | 75 | return Status::OK(); |
492 | 75 | } |
493 | | |
494 | | Status DeleteHandler::convert_to_sub_pred_v2(DeletePredicatePB* delete_pred, |
495 | 0 | TabletSchemaSPtr schema) { |
496 | 0 | if (!delete_pred->sub_predicates().empty() && delete_pred->sub_predicates_v2().empty()) { |
497 | 0 | for (const auto& condition_str : delete_pred->sub_predicates()) { |
498 | 0 | auto* sub_pred = delete_pred->add_sub_predicates_v2(); |
499 | 0 | auto condition = parse_condition(condition_str); |
500 | 0 | const auto& column = *DORIS_TRY(schema->column(condition.column_name)); |
501 | 0 | sub_pred->set_column_unique_id(column.unique_id()); |
502 | 0 | sub_pred->set_column_name(condition.column_name); |
503 | 0 | sub_pred->set_op(type_to_op_str(condition.condition_op)); |
504 | 0 | sub_pred->set_cond_value(condition.value_str.front()); |
505 | 0 | } |
506 | 0 | } |
507 | | |
508 | 0 | auto* in_pred_list = delete_pred->mutable_in_predicates(); |
509 | 0 | for (auto& in_pred : *in_pred_list) { |
510 | 0 | const auto& column = *DORIS_TRY(schema->column(in_pred.column_name())); |
511 | 0 | in_pred.set_column_unique_id(column.unique_id()); |
512 | 0 | } |
513 | 0 | return Status::OK(); |
514 | 0 | } |
515 | | |
516 | | bool DeleteHandler::is_condition_value_valid(const TabletColumn& column, |
517 | | const std::string& condition_op, |
518 | 140 | const string& value_str) { |
519 | 140 | if ("IS" == condition_op && ("NULL" == value_str || "NOT NULL" == value_str)) { |
520 | 2 | return true; |
521 | 2 | } |
522 | | |
523 | 138 | FieldType field_type = column.type(); |
524 | 138 | switch (field_type) { |
525 | 11 | case FieldType::OLAP_FIELD_TYPE_TINYINT: |
526 | 11 | return valid_signed_number<int8_t>(value_str); |
527 | 13 | case FieldType::OLAP_FIELD_TYPE_SMALLINT: |
528 | 13 | return valid_signed_number<int16_t>(value_str); |
529 | 54 | case FieldType::OLAP_FIELD_TYPE_INT: |
530 | 54 | return valid_signed_number<int32_t>(value_str); |
531 | 5 | case FieldType::OLAP_FIELD_TYPE_BIGINT: |
532 | 5 | return valid_signed_number<int64_t>(value_str); |
533 | 4 | case FieldType::OLAP_FIELD_TYPE_LARGEINT: |
534 | 4 | return valid_signed_number<int128_t>(value_str); |
535 | 0 | case FieldType::OLAP_FIELD_TYPE_UNSIGNED_TINYINT: |
536 | 0 | return valid_unsigned_number<uint8_t>(value_str); |
537 | 0 | case FieldType::OLAP_FIELD_TYPE_UNSIGNED_SMALLINT: |
538 | 0 | return valid_unsigned_number<uint16_t>(value_str); |
539 | 0 | case FieldType::OLAP_FIELD_TYPE_UNSIGNED_INT: |
540 | 0 | return valid_unsigned_number<uint32_t>(value_str); |
541 | 0 | case FieldType::OLAP_FIELD_TYPE_UNSIGNED_BIGINT: |
542 | 0 | return valid_unsigned_number<uint64_t>(value_str); |
543 | 7 | case FieldType::OLAP_FIELD_TYPE_DECIMAL: |
544 | 7 | return valid_decimal(value_str, column.precision(), column.frac()); |
545 | 0 | case FieldType::OLAP_FIELD_TYPE_DECIMAL32: |
546 | 0 | return valid_decimal(value_str, column.precision(), column.frac()); |
547 | 0 | case FieldType::OLAP_FIELD_TYPE_DECIMAL64: |
548 | 0 | return valid_decimal(value_str, column.precision(), column.frac()); |
549 | 0 | case FieldType::OLAP_FIELD_TYPE_DECIMAL128I: |
550 | 0 | return valid_decimal(value_str, column.precision(), column.frac()); |
551 | 0 | case FieldType::OLAP_FIELD_TYPE_DECIMAL256: |
552 | 0 | return valid_decimal(value_str, column.precision(), column.frac()); |
553 | 3 | case FieldType::OLAP_FIELD_TYPE_CHAR: |
554 | 7 | case FieldType::OLAP_FIELD_TYPE_VARCHAR: |
555 | 7 | return value_str.size() <= column.length(); |
556 | 0 | case FieldType::OLAP_FIELD_TYPE_STRING: |
557 | 0 | return value_str.size() <= config::string_type_length_soft_limit_bytes; |
558 | 5 | case FieldType::OLAP_FIELD_TYPE_DATE: |
559 | 11 | case FieldType::OLAP_FIELD_TYPE_DATETIME: |
560 | 11 | case FieldType::OLAP_FIELD_TYPE_DATEV2: |
561 | 11 | case FieldType::OLAP_FIELD_TYPE_DATETIMEV2: |
562 | 24 | case FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ: |
563 | 24 | return valid_datetime(value_str, column.frac()); |
564 | 0 | case FieldType::OLAP_FIELD_TYPE_BOOL: |
565 | 0 | return valid_bool(value_str); |
566 | 5 | case FieldType::OLAP_FIELD_TYPE_IPV4: |
567 | 5 | return valid_ipv4(value_str); |
568 | 8 | case FieldType::OLAP_FIELD_TYPE_IPV6: |
569 | 8 | return valid_ipv6(value_str); |
570 | 0 | default: |
571 | 0 | LOG(WARNING) << "unknown field type. [type=" << int(field_type) << "]"; |
572 | 138 | } |
573 | 0 | return false; |
574 | 138 | } |
575 | | |
576 | 135 | Status DeleteHandler::check_condition_valid(const TabletSchema& schema, const TCondition& cond) { |
577 | | // Check whether the column exists |
578 | 135 | int32_t field_index = schema.field_index(cond.column_name); |
579 | 135 | if (field_index < 0) { |
580 | 1 | return Status::Error<ErrorCode::INVALID_ARGUMENT>("field is not existent. [field_index={}]", |
581 | 1 | field_index); |
582 | 1 | } |
583 | | |
584 | | // Delete condition should only applied on key columns or duplicate key table, and |
585 | | // the condition column type should not be float or double. |
586 | 134 | const TabletColumn& column = schema.column(field_index); |
587 | | |
588 | 134 | if (column.type() == FieldType::OLAP_FIELD_TYPE_DOUBLE || |
589 | 134 | column.type() == FieldType::OLAP_FIELD_TYPE_FLOAT) { |
590 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>("data type is float or double."); |
591 | 0 | } |
592 | | |
593 | | // Check operator and operands size are matched. |
594 | 134 | if ("*=" != cond.condition_op && "!*=" != cond.condition_op && |
595 | 134 | cond.condition_values.size() != 1) { |
596 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition value size. [size={}]", |
597 | 0 | cond.condition_values.size()); |
598 | 0 | } |
599 | | |
600 | | // Check each operand is valid |
601 | 140 | for (const auto& condition_value : cond.condition_values) { |
602 | 140 | if (!is_condition_value_valid(column, cond.condition_op, condition_value)) { |
603 | 29 | return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition value. [value={}]", |
604 | 29 | condition_value); |
605 | 29 | } |
606 | 140 | } |
607 | | |
608 | 105 | if (!cond.__isset.column_unique_id) { |
609 | 105 | LOG(WARNING) << "column=" << cond.column_name |
610 | 105 | << " in predicate does not have uid, table id=" << schema.table_id(); |
611 | | // TODO(tsy): make it fail here after FE forbidding hard-link-schema-change |
612 | 105 | return Status::OK(); |
613 | 105 | } |
614 | 0 | if (schema.field_index(cond.column_unique_id) == -1) { |
615 | 0 | const auto& err_msg = |
616 | 0 | fmt::format("column id does not exists in table={}, schema version={},", |
617 | 0 | schema.table_id(), schema.schema_version()); |
618 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>(err_msg); |
619 | 0 | } |
620 | 0 | if (!iequal(schema.column_by_uid(cond.column_unique_id).name(), cond.column_name)) { |
621 | 0 | const auto& err_msg = fmt::format( |
622 | 0 | "colum name={} does not belongs to column uid={}, which " |
623 | 0 | "column name={}, " |
624 | 0 | "delete_cond.column_name ={}", |
625 | 0 | cond.column_name, cond.column_unique_id, |
626 | 0 | schema.column_by_uid(cond.column_unique_id).name(), cond.column_name); |
627 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>(err_msg); |
628 | 0 | } |
629 | | |
630 | 0 | return Status::OK(); |
631 | 0 | } |
632 | | |
633 | | PredicateType DeleteHandler::parse_condition_op(const std::string& op_str, |
634 | 302 | const std::list<std::string>& cond_values) { |
635 | 302 | if (trim(to_lower(op_str)) == "=") { |
636 | 92 | return PredicateType::EQ; |
637 | 210 | } else if (trim(to_lower(op_str)) == "!=") { |
638 | 18 | return PredicateType::NE; |
639 | 192 | } else if (trim(to_lower(op_str)) == ">>") { |
640 | 9 | return PredicateType::GT; |
641 | 183 | } else if (trim(to_lower(op_str)) == "<<") { |
642 | 129 | return PredicateType::LT; |
643 | 129 | } else if (trim(to_lower(op_str)) == ">=") { |
644 | 5 | return PredicateType::GE; |
645 | 49 | } else if (trim(to_lower(op_str)) == "<=") { |
646 | 7 | return PredicateType::LE; |
647 | 42 | } else if (trim(to_lower(op_str)) == "*=") { |
648 | 0 | return cond_values.size() > 1 ? PredicateType::IN_LIST : PredicateType::EQ; |
649 | 42 | } else if (trim(to_lower(op_str)) == "!*=") { |
650 | 0 | return cond_values.size() > 1 ? PredicateType::NOT_IN_LIST : PredicateType::NE; |
651 | 42 | } else if (trim(to_lower(op_str)) == "is") { |
652 | 42 | return to_lower(cond_values.front()) == "null" ? PredicateType::IS_NULL |
653 | 42 | : PredicateType::IS_NOT_NULL; |
654 | 42 | } else { |
655 | 0 | throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>( |
656 | 0 | "invalid condition operator. operator={}", op_str)); |
657 | 0 | } |
658 | 0 | return PredicateType::UNKNOWN; |
659 | 302 | } |
660 | | |
661 | | DeleteHandler::ConditionParseResult DeleteHandler::parse_condition( |
662 | 100 | const DeleteSubPredicatePB& sub_cond) { |
663 | 100 | ConditionParseResult res; |
664 | 100 | if (!sub_cond.has_column_name() || !sub_cond.has_op() || !sub_cond.has_cond_value()) { |
665 | 0 | throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>( |
666 | 0 | "fail to parse condition. condition={} {} {}", sub_cond.column_name(), |
667 | 0 | sub_cond.op(), sub_cond.cond_value())); |
668 | 0 | } |
669 | 100 | if (sub_cond.has_column_unique_id()) { |
670 | 0 | res.col_unique_id = sub_cond.column_unique_id(); |
671 | 0 | } |
672 | 100 | res.column_name = sub_cond.column_name(); |
673 | 100 | res.value_str.push_back(sub_cond.cond_value()); |
674 | 100 | res.condition_op = parse_condition_op(sub_cond.op(), res.value_str); |
675 | 100 | return res; |
676 | 100 | } |
677 | | |
678 | | // clang-format off |
679 | | // Condition string format, the format is (column_name)(op)(value) |
680 | | // eg: condition_str="c1 = 1597751948193618247 and length(source)<1;\n;\n" |
681 | | // column_name: matches "c1", must include FeNameFormat.java COLUMN_NAME_REGEX |
682 | | // and compactible with any the lagacy |
683 | | // operator: matches "=" |
684 | | // value: matches "1597751948193618247 and length(source)<1;\n;\n" |
685 | | // |
686 | | // For more info, see DeleteHandler::construct_sub_predicates |
687 | | // FIXME(gavin): This is a tricky implementation, it should not be the final resolution, refactor it. |
688 | | const char* const CONDITION_STR_PATTERN = |
689 | | // .----------------- column-name --------------------------. .----------------------- operator ------------------------. .------------ value ----------. |
690 | | R"(([_a-zA-Z@0-9\s/\p{L}][.a-zA-Z0-9_+-/?@#$%^&*"\s,:\p{L}]*)\s*((?:=)|(?:!=)|(?:>>)|(?:<<)|(?:>=)|(?:<=)|(?:\*=)|(?: IS ))\s*('((?:[\s\S]+)?)'|(?:[\s\S]+)?))"; |
691 | | // '----------------- group 1 ------------------------------' '--------------------- group 2 ---------------------------' | '-- group 4--' | |
692 | | // match any of: = != >> << >= <= *= " IS " '----------- group 3 ---------' |
693 | | // match **ANY THING** without(4) |
694 | | // or with(3) single quote |
695 | | // clang-format on |
696 | | RE2 DELETE_HANDLER_REGEX(CONDITION_STR_PATTERN); |
697 | | |
698 | | DeleteHandler::ConditionParseResult DeleteHandler::parse_condition( |
699 | 182 | const std::string& condition_str) { |
700 | 182 | ConditionParseResult res; |
701 | 182 | std::string col_name, op, value, g4; |
702 | | |
703 | 182 | bool matched = RE2::FullMatch(condition_str, DELETE_HANDLER_REGEX, &col_name, &op, &value, |
704 | 182 | &g4); // exact match |
705 | | |
706 | 182 | if (!matched) { |
707 | 0 | throw Exception( |
708 | 0 | Status::InvalidArgument("fail to sub condition. condition={}", condition_str)); |
709 | 0 | } |
710 | | |
711 | 182 | res.column_name = col_name; |
712 | | |
713 | | // match string with single quotes, a = b or a = 'b' |
714 | 182 | if (!g4.empty()) { |
715 | 141 | res.value_str.push_back(g4); |
716 | 141 | } else { |
717 | 41 | res.value_str.push_back(value); |
718 | 41 | } |
719 | 182 | res.condition_op = DeleteHandler::parse_condition_op(op, res.value_str); |
720 | 182 | VLOG_NOTICE << "parsed condition_str: col_name={" << col_name << "} op={" << op << "} val={" |
721 | 50 | << res.value_str.back() << "}"; |
722 | 182 | return res; |
723 | 182 | } |
724 | | |
725 | | template <typename SubPredType> |
726 | | requires(std::is_same_v<SubPredType, DeleteSubPredicatePB> or |
727 | | std::is_same_v<SubPredType, std::string>) |
728 | | Status DeleteHandler::_parse_column_pred(TabletSchemaSPtr complete_schema, |
729 | | TabletSchemaSPtr delete_pred_related_schema, |
730 | | const RepeatedPtrField<SubPredType>& sub_pred_list, |
731 | 169 | DeleteConditions* delete_conditions) { |
732 | 181 | for (const auto& sub_predicate : sub_pred_list) { |
733 | 181 | auto condition = parse_condition(sub_predicate); |
734 | 181 | int32_t col_unique_id = -1; |
735 | 181 | if constexpr (std::is_same_v<SubPredType, DeleteSubPredicatePB>) { |
736 | 100 | if (sub_predicate.has_column_unique_id()) [[likely]] { |
737 | 0 | col_unique_id = sub_predicate.column_unique_id(); |
738 | 0 | } |
739 | 100 | } |
740 | 181 | if (col_unique_id < 0) { |
741 | 181 | const auto& column = |
742 | 181 | *DORIS_TRY(delete_pred_related_schema->column(condition.column_name)); |
743 | 181 | col_unique_id = column.unique_id(); |
744 | 181 | } |
745 | 181 | condition.col_unique_id = col_unique_id; |
746 | 181 | const auto& column = complete_schema->column_by_uid(col_unique_id); |
747 | 181 | uint32_t index = complete_schema->field_index(col_unique_id); |
748 | 181 | std::shared_ptr<ColumnPredicate> predicate; |
749 | 181 | RETURN_IF_ERROR(parse_to_predicate(index, column.name(), column.get_vec_type(), condition, |
750 | 181 | _predicate_arena, predicate)); |
751 | 174 | if (predicate != nullptr) { |
752 | 174 | delete_conditions->column_predicate_vec.push_back(predicate); |
753 | 174 | } |
754 | 174 | } |
755 | 162 | return Status::OK(); |
756 | 169 | } _ZN5doris13DeleteHandler18_parse_column_predINS_20DeleteSubPredicatePBEQoosr3stdE9is_same_vIT_S2_Esr3stdE9is_same_vIS3_NSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEEEENS_6StatusESt10shared_ptrINS_12TabletSchemaEESD_RKN6google8protobuf16RepeatedPtrFieldIS3_EEPNS_16DeleteConditionsE Line | Count | Source | 731 | 87 | DeleteConditions* delete_conditions) { | 732 | 100 | for (const auto& sub_predicate : sub_pred_list) { | 733 | 100 | auto condition = parse_condition(sub_predicate); | 734 | 100 | int32_t col_unique_id = -1; | 735 | 100 | if constexpr (std::is_same_v<SubPredType, DeleteSubPredicatePB>) { | 736 | 100 | if (sub_predicate.has_column_unique_id()) [[likely]] { | 737 | 0 | col_unique_id = sub_predicate.column_unique_id(); | 738 | 0 | } | 739 | 100 | } | 740 | 100 | if (col_unique_id < 0) { | 741 | 100 | const auto& column = | 742 | 100 | *DORIS_TRY(delete_pred_related_schema->column(condition.column_name)); | 743 | 100 | col_unique_id = column.unique_id(); | 744 | 100 | } | 745 | 100 | condition.col_unique_id = col_unique_id; | 746 | 100 | const auto& column = complete_schema->column_by_uid(col_unique_id); | 747 | 100 | uint32_t index = complete_schema->field_index(col_unique_id); | 748 | 100 | std::shared_ptr<ColumnPredicate> predicate; | 749 | 100 | RETURN_IF_ERROR(parse_to_predicate(index, column.name(), column.get_vec_type(), condition, | 750 | 100 | _predicate_arena, predicate)); | 751 | 100 | if (predicate != nullptr) { | 752 | 100 | delete_conditions->column_predicate_vec.push_back(predicate); | 753 | 100 | } | 754 | 100 | } | 755 | 87 | return Status::OK(); | 756 | 87 | } |
_ZN5doris13DeleteHandler18_parse_column_predINSt7__cxx1112basic_stringIcSt11char_traitsIcESaIcEEEQoosr3stdE9is_same_vIT_NS_20DeleteSubPredicatePBEEsr3stdE9is_same_vIS8_S7_EEENS_6StatusESt10shared_ptrINS_12TabletSchemaEESD_RKN6google8protobuf16RepeatedPtrFieldIS8_EEPNS_16DeleteConditionsE Line | Count | Source | 731 | 82 | DeleteConditions* delete_conditions) { | 732 | 82 | for (const auto& sub_predicate : sub_pred_list) { | 733 | 81 | auto condition = parse_condition(sub_predicate); | 734 | 81 | int32_t col_unique_id = -1; | 735 | | if constexpr (std::is_same_v<SubPredType, DeleteSubPredicatePB>) { | 736 | | if (sub_predicate.has_column_unique_id()) [[likely]] { | 737 | | col_unique_id = sub_predicate.column_unique_id(); | 738 | | } | 739 | | } | 740 | 81 | if (col_unique_id < 0) { | 741 | 81 | const auto& column = | 742 | 81 | *DORIS_TRY(delete_pred_related_schema->column(condition.column_name)); | 743 | 81 | col_unique_id = column.unique_id(); | 744 | 81 | } | 745 | 81 | condition.col_unique_id = col_unique_id; | 746 | 81 | const auto& column = complete_schema->column_by_uid(col_unique_id); | 747 | 81 | uint32_t index = complete_schema->field_index(col_unique_id); | 748 | 81 | std::shared_ptr<ColumnPredicate> predicate; | 749 | 81 | RETURN_IF_ERROR(parse_to_predicate(index, column.name(), column.get_vec_type(), condition, | 750 | 81 | _predicate_arena, predicate)); | 751 | 74 | if (predicate != nullptr) { | 752 | 74 | delete_conditions->column_predicate_vec.push_back(predicate); | 753 | 74 | } | 754 | 74 | } | 755 | 75 | return Status::OK(); | 756 | 82 | } |
|
757 | | |
758 | | Status DeleteHandler::init(TabletSchemaSPtr tablet_schema, |
759 | 371 | const std::vector<RowsetMetaSharedPtr>& delete_preds, int64_t version) { |
760 | 371 | DCHECK(!_is_inited) << "reinitialize delete handler."; |
761 | 371 | DCHECK(version >= 0) << "invalid parameters. version=" << version; |
762 | | |
763 | 371 | for (const auto& delete_pred : delete_preds) { |
764 | | // Skip the delete condition with large version |
765 | 169 | if (delete_pred->version().first > version) { |
766 | 0 | continue; |
767 | 0 | } |
768 | | // Need the tablet schema at the delete condition to parse the accurate column |
769 | 169 | const auto& delete_pred_related_schema = delete_pred->tablet_schema(); |
770 | 169 | const auto& delete_condition = delete_pred->delete_predicate(); |
771 | 169 | DeleteConditions temp; |
772 | 169 | temp.filter_version = delete_pred->version().first; |
773 | 169 | if (!delete_condition.sub_predicates_v2().empty()) { |
774 | 87 | RETURN_IF_ERROR(_parse_column_pred(tablet_schema, delete_pred_related_schema, |
775 | 87 | delete_condition.sub_predicates_v2(), &temp)); |
776 | 87 | } else { |
777 | | // make it compatible with the former versions |
778 | 82 | RETURN_IF_ERROR(_parse_column_pred(tablet_schema, delete_pred_related_schema, |
779 | 82 | delete_condition.sub_predicates(), &temp)); |
780 | 82 | } |
781 | 162 | for (const auto& in_predicate : delete_condition.in_predicates()) { |
782 | 2 | ConditionParseResult condition; |
783 | 2 | condition.column_name = in_predicate.column_name(); |
784 | | |
785 | 2 | int32_t col_unique_id = -1; |
786 | 2 | if (in_predicate.has_column_unique_id()) { |
787 | 0 | col_unique_id = in_predicate.column_unique_id(); |
788 | 2 | } else { |
789 | | // if upgrade from version 2.0.x, column_unique_id maybe not set |
790 | 2 | const auto& pre_column = |
791 | 2 | *DORIS_TRY(delete_pred_related_schema->column(condition.column_name)); |
792 | 2 | col_unique_id = pre_column.unique_id(); |
793 | 2 | } |
794 | 2 | if (col_unique_id == -1) { |
795 | 0 | return Status::Error<ErrorCode::DELETE_INVALID_CONDITION>( |
796 | 0 | "cannot get column_unique_id for column {}", condition.column_name); |
797 | 0 | } |
798 | 2 | condition.col_unique_id = col_unique_id; |
799 | | |
800 | 2 | condition.condition_op = |
801 | 2 | in_predicate.is_not_in() ? PredicateType::NOT_IN_LIST : PredicateType::IN_LIST; |
802 | 5 | for (const auto& value : in_predicate.values()) { |
803 | 5 | condition.value_str.push_back(value); |
804 | 5 | } |
805 | 2 | const auto& column = tablet_schema->column_by_uid(col_unique_id); |
806 | 2 | uint32_t index = tablet_schema->field_index(col_unique_id); |
807 | 2 | std::shared_ptr<ColumnPredicate> predicate; |
808 | 2 | RETURN_IF_ERROR(parse_to_in_predicate(index, column.name(), column.get_vec_type(), |
809 | 2 | condition, _predicate_arena, predicate)); |
810 | 2 | temp.column_predicate_vec.push_back(predicate); |
811 | 2 | } |
812 | | |
813 | 162 | _del_conds.emplace_back(std::move(temp)); |
814 | 162 | } |
815 | | |
816 | 364 | _is_inited = true; |
817 | | |
818 | 364 | return Status::OK(); |
819 | 371 | } |
820 | | |
821 | 388 | DeleteHandler::~DeleteHandler() { |
822 | 388 | if (!_is_inited) { |
823 | 24 | return; |
824 | 24 | } |
825 | | |
826 | 364 | _del_conds.clear(); |
827 | 364 | _is_inited = false; |
828 | 364 | } |
829 | | |
830 | | void DeleteHandler::get_delete_conditions_after_version( |
831 | | int64_t version, AndBlockColumnPredicate* and_block_column_predicate_ptr, |
832 | | std::unordered_map<int32_t, std::vector<std::shared_ptr<const ColumnPredicate>>>* |
833 | 1.07k | del_predicates_for_zone_map) const { |
834 | 1.07k | for (const auto& del_cond : _del_conds) { |
835 | 555 | if (del_cond.filter_version > version) { |
836 | | // now, only query support delete column predicate operator |
837 | 406 | if (!del_cond.column_predicate_vec.empty()) { |
838 | 406 | if (del_cond.column_predicate_vec.size() == 1) { |
839 | 406 | auto single_column_block_predicate = SingleColumnBlockPredicate::create_unique( |
840 | 406 | del_cond.column_predicate_vec[0]); |
841 | 406 | and_block_column_predicate_ptr->add_column_predicate( |
842 | 406 | std::move(single_column_block_predicate)); |
843 | 406 | if (del_predicates_for_zone_map->count( |
844 | 406 | del_cond.column_predicate_vec[0]->column_id()) < 1) { |
845 | 406 | del_predicates_for_zone_map->insert( |
846 | 406 | {del_cond.column_predicate_vec[0]->column_id(), |
847 | 406 | std::vector<std::shared_ptr<const ColumnPredicate>> {}}); |
848 | 406 | } |
849 | 406 | (*del_predicates_for_zone_map)[del_cond.column_predicate_vec[0]->column_id()] |
850 | 406 | .push_back(del_cond.column_predicate_vec[0]); |
851 | 406 | } else { |
852 | 0 | auto or_column_predicate = OrBlockColumnPredicate::create_unique(); |
853 | | |
854 | | // build or_column_predicate |
855 | | // when delete from where a = 1 and b = 2, we can not use del_predicates_for_zone_map to filter zone page, |
856 | | // so here do not put predicate to del_predicates_for_zone_map, |
857 | | // refer #17145 for more details. |
858 | | // // TODO: need refactor design and code to use more version delete and more column delete to filter zone page. |
859 | 0 | std::for_each(del_cond.column_predicate_vec.cbegin(), |
860 | 0 | del_cond.column_predicate_vec.cend(), |
861 | 0 | [&or_column_predicate]( |
862 | 0 | const std::shared_ptr<const ColumnPredicate> predicate) { |
863 | 0 | or_column_predicate->add_column_predicate( |
864 | 0 | SingleColumnBlockPredicate::create_unique(predicate)); |
865 | 0 | }); |
866 | 0 | and_block_column_predicate_ptr->add_column_predicate( |
867 | 0 | std::move(or_column_predicate)); |
868 | 0 | } |
869 | 406 | } |
870 | 406 | } |
871 | 555 | } |
872 | 1.07k | } |
873 | | |
874 | | } // namespace doris |