/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 = \ |
256 | 10 | create_comparison_predicate0<PredicateType::EQ>(index, type, v, true, arena); \ |
257 | 10 | return Status::OK(); \ |
258 | 7 | case PredicateType::NE: \ |
259 | 7 | predicate = \ |
260 | 7 | create_comparison_predicate0<PredicateType::NE>(index, type, v, true, arena); \ |
261 | 7 | return Status::OK(); \ |
262 | 2 | case PredicateType::GT: \ |
263 | 2 | predicate = \ |
264 | 2 | create_comparison_predicate0<PredicateType::GT>(index, type, v, true, arena); \ |
265 | 2 | return Status::OK(); \ |
266 | 2 | case PredicateType::GE: \ |
267 | 2 | predicate = \ |
268 | 2 | create_comparison_predicate0<PredicateType::GE>(index, type, v, true, arena); \ |
269 | 2 | return Status::OK(); \ |
270 | 76 | case PredicateType::LT: \ |
271 | 76 | predicate = \ |
272 | 76 | create_comparison_predicate0<PredicateType::LT>(index, type, v, true, arena); \ |
273 | 76 | return Status::OK(); \ |
274 | 2 | case PredicateType::LE: \ |
275 | 2 | predicate = \ |
276 | 2 | create_comparison_predicate0<PredicateType::LE>(index, type, v, 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 vectorized::DataTypePtr& type, |
284 | | DeleteHandler::ConditionParseResult& res, vectorized::Arena& arena, |
285 | 181 | std::shared_ptr<ColumnPredicate>& predicate) { |
286 | 181 | DCHECK_EQ(res.value_str.size(), 1); |
287 | 181 | if (res.condition_op == PredicateType::IS_NULL || |
288 | 181 | res.condition_op == PredicateType::IS_NOT_NULL) { |
289 | 37 | predicate = NullPredicate::create_shared( |
290 | 37 | index, res.condition_op == PredicateType::IS_NOT_NULL, type->get_primitive_type()); |
291 | 37 | return Status::OK(); |
292 | 37 | } |
293 | 144 | StringRef v; |
294 | 144 | switch (type->get_primitive_type()) { |
295 | 16 | CONVERT_CASE(TYPE_TINYINT); |
296 | 16 | CONVERT_CASE(TYPE_SMALLINT); |
297 | 150 | CONVERT_CASE(TYPE_INT); |
298 | 0 | CONVERT_CASE(TYPE_BIGINT); |
299 | 0 | CONVERT_CASE(TYPE_LARGEINT); |
300 | 0 | CONVERT_CASE(TYPE_FLOAT); |
301 | 0 | CONVERT_CASE(TYPE_DOUBLE); |
302 | 0 | CONVERT_CASE(TYPE_DATE); |
303 | 0 | CONVERT_CASE(TYPE_DATETIME); |
304 | 0 | CONVERT_CASE(TYPE_DATEV2); |
305 | 0 | CONVERT_CASE(TYPE_DATETIMEV2); |
306 | 21 | CONVERT_CASE(TYPE_TIMESTAMPTZ); |
307 | 0 | CONVERT_CASE(TYPE_BOOLEAN); |
308 | 2 | CONVERT_CASE(TYPE_IPV4); |
309 | 0 | CONVERT_CASE(TYPE_IPV6); |
310 | 0 | CONVERT_CASE(TYPE_DECIMALV2); |
311 | 0 | CONVERT_CASE(TYPE_DECIMAL32); |
312 | 0 | CONVERT_CASE(TYPE_DECIMAL64); |
313 | 0 | CONVERT_CASE(TYPE_DECIMAL128I); |
314 | 0 | CONVERT_CASE(TYPE_DECIMAL256); |
315 | 0 | case TYPE_CHAR: |
316 | 0 | case TYPE_VARCHAR: |
317 | 38 | case TYPE_STRING: { |
318 | 38 | RETURN_IF_ERROR(convert<TYPE_STRING>(type, res.value_str.front(), arena, v)); |
319 | 38 | switch (res.condition_op) { |
320 | 38 | case PredicateType::EQ: |
321 | 38 | predicate = |
322 | 38 | create_comparison_predicate0<PredicateType::EQ>(index, type, v, true, arena); |
323 | 38 | return Status::OK(); |
324 | 0 | case PredicateType::NE: |
325 | 0 | predicate = |
326 | 0 | create_comparison_predicate0<PredicateType::NE>(index, type, v, true, arena); |
327 | 0 | return Status::OK(); |
328 | 0 | case PredicateType::GT: |
329 | 0 | predicate = |
330 | 0 | create_comparison_predicate0<PredicateType::GT>(index, type, v, true, arena); |
331 | 0 | return Status::OK(); |
332 | 0 | case PredicateType::GE: |
333 | 0 | predicate = |
334 | 0 | create_comparison_predicate0<PredicateType::GE>(index, type, v, true, arena); |
335 | 0 | return Status::OK(); |
336 | 0 | case PredicateType::LT: |
337 | 0 | predicate = |
338 | 0 | create_comparison_predicate0<PredicateType::LT>(index, type, v, true, arena); |
339 | 0 | return Status::OK(); |
340 | 0 | case PredicateType::LE: |
341 | 0 | predicate = |
342 | 0 | create_comparison_predicate0<PredicateType::LE>(index, type, v, true, arena); |
343 | 0 | return Status::OK(); |
344 | 0 | default: |
345 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
346 | 0 | "invalid condition operator. operator={}", type_to_op_str(res.condition_op)); |
347 | 38 | } |
348 | 0 | break; |
349 | 38 | } |
350 | 0 | default: |
351 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
352 | 0 | "unsupported data type in delete handler. type={}", |
353 | 0 | type_to_string(type->get_primitive_type())); |
354 | 144 | } |
355 | 0 | return Status::OK(); |
356 | 144 | #undef CONVERT_CASE |
357 | 144 | } |
358 | | |
359 | | Status parse_to_in_predicate(const uint32_t index, const vectorized::DataTypePtr& type, |
360 | | DeleteHandler::ConditionParseResult& res, vectorized::Arena& arena, |
361 | 2 | std::shared_ptr<ColumnPredicate>& predicate) { |
362 | 2 | DCHECK_GT(res.value_str.size(), 1); |
363 | 2 | switch (res.condition_op) { |
364 | 1 | case PredicateType::IN_LIST: { |
365 | 1 | std::shared_ptr<HybridSetBase> set; |
366 | 1 | RETURN_IF_ERROR(convert(type, res.value_str, arena, set)); |
367 | 1 | predicate = create_in_list_predicate<PredicateType::IN_LIST>(index, type, set, true); |
368 | 1 | break; |
369 | 1 | } |
370 | 1 | case PredicateType::NOT_IN_LIST: { |
371 | 1 | std::shared_ptr<HybridSetBase> set; |
372 | 1 | RETURN_IF_ERROR(convert(type, res.value_str, arena, set)); |
373 | 1 | predicate = create_in_list_predicate<PredicateType::NOT_IN_LIST>(index, type, set, true); |
374 | 1 | break; |
375 | 1 | } |
376 | 0 | default: |
377 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition operator. operator={}", |
378 | 0 | type_to_op_str(res.condition_op)); |
379 | 2 | } |
380 | 2 | return Status::OK(); |
381 | 2 | } |
382 | | |
383 | | // construct sub condition from TCondition |
384 | 101 | std::string construct_sub_predicate(const TCondition& condition) { |
385 | 101 | string op = condition.condition_op; |
386 | 101 | if (op == "<") { |
387 | 50 | op += "<"; |
388 | 51 | } else if (op == ">") { |
389 | 3 | op += ">"; |
390 | 3 | } |
391 | 101 | string condition_str; |
392 | 101 | if ("IS" == op) { |
393 | | // ATTN: tricky! Surround IS with spaces to make it "special" |
394 | 2 | condition_str = condition.column_name + " IS " + condition.condition_values[0]; |
395 | 99 | } else { // multi-elements IN expr has been processed with InPredicatePB |
396 | 99 | if (op == "*=") { |
397 | 2 | op = "="; |
398 | 97 | } else if (op == "!*=") { |
399 | 2 | op = "!="; |
400 | 2 | } |
401 | 99 | condition_str = condition.column_name + op + "'" + condition.condition_values[0] + "'"; |
402 | 99 | } |
403 | 101 | return condition_str; |
404 | 101 | } |
405 | | |
406 | | // make operators from FE adaptive to BE |
407 | 101 | std::string trans_op(const std::string& opt) { |
408 | 101 | std::string op = string(opt); |
409 | 101 | if (op == "<") { |
410 | 50 | op += "<"; |
411 | 51 | } else if (op == ">") { |
412 | 3 | op += ">"; |
413 | 3 | } |
414 | 101 | if ("IS" != op) { |
415 | 99 | if (op == "*=") { |
416 | 2 | op = "="; |
417 | 97 | } else if (op == "!*=") { |
418 | 2 | op = "!="; |
419 | 2 | } |
420 | 99 | } |
421 | 101 | return op; |
422 | 101 | } |
423 | | |
424 | | Status DeleteHandler::generate_delete_predicate(const TabletSchema& schema, |
425 | | const std::vector<TCondition>& conditions, |
426 | 106 | DeletePredicatePB* del_pred) { |
427 | 106 | DBUG_EXECUTE_IF("DeleteHandler::generate_delete_predicate.inject_failure", { |
428 | 106 | return Status::Error<false>(dp->param<int>("error_code"), |
429 | 106 | dp->param<std::string>("error_msg")); |
430 | 106 | }) |
431 | 106 | if (conditions.empty()) { |
432 | 1 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
433 | 1 | "invalid parameters for store_cond. condition_size={}", conditions.size()); |
434 | 1 | } |
435 | | |
436 | | // Check whether the delete condition meets the requirements |
437 | 135 | for (const TCondition& condition : conditions) { |
438 | 135 | RETURN_IF_ERROR(check_condition_valid(schema, condition)); |
439 | 135 | } |
440 | | |
441 | | // Store delete condition |
442 | 105 | for (const TCondition& condition : conditions) { |
443 | 105 | if (condition.condition_values.size() > 1) { |
444 | 4 | InPredicatePB* in_pred = del_pred->add_in_predicates(); |
445 | 4 | if (condition.__isset.column_unique_id) { |
446 | 0 | in_pred->set_column_unique_id(condition.column_unique_id); |
447 | 0 | } |
448 | 4 | in_pred->set_column_name(condition.column_name); |
449 | 4 | bool is_not_in = condition.condition_op == "!*="; |
450 | 4 | in_pred->set_is_not_in(is_not_in); |
451 | 10 | for (const auto& condition_value : condition.condition_values) { |
452 | 10 | in_pred->add_values(condition_value); |
453 | 10 | } |
454 | | |
455 | 4 | LOG(INFO) << "store one sub-delete condition. condition name=" << in_pred->column_name() |
456 | 4 | << "condition size=" << in_pred->values().size(); |
457 | 101 | } else { |
458 | | // write sub predicate v1 for compactbility |
459 | 101 | std::string condition_str = construct_sub_predicate(condition); |
460 | 101 | VLOG_NOTICE << __PRETTY_FUNCTION__ << " condition_str: " << condition_str; |
461 | 101 | del_pred->add_sub_predicates(condition_str); |
462 | 101 | DeleteSubPredicatePB* sub_predicate = del_pred->add_sub_predicates_v2(); |
463 | 101 | if (condition.__isset.column_unique_id) { |
464 | | // only light schema change capable table set this field |
465 | 0 | sub_predicate->set_column_unique_id(condition.column_unique_id); |
466 | 101 | } else { |
467 | 101 | try { |
468 | 101 | [[maybe_unused]] auto parsed_cond = parse_condition(condition_str); |
469 | 101 | } catch (const Exception& e) { |
470 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>( |
471 | 0 | "failed to parse condition_str, condition={}, error={}", |
472 | 0 | ThriftDebugString(condition), e.to_string()); |
473 | 0 | } |
474 | 101 | } |
475 | | |
476 | 101 | sub_predicate->set_column_name(condition.column_name); |
477 | 101 | sub_predicate->set_op(trans_op(condition.condition_op)); |
478 | 101 | sub_predicate->set_cond_value(condition.condition_values[0]); |
479 | 101 | LOG(INFO) << "store one sub-delete condition. condition=" |
480 | 101 | << fmt::format(" {} {} {}", condition.column_name, condition.condition_op, |
481 | 101 | condition.condition_values[0]); |
482 | 101 | } |
483 | 105 | } |
484 | 75 | del_pred->set_version(-1); |
485 | | |
486 | 75 | return Status::OK(); |
487 | 75 | } |
488 | | |
489 | | Status DeleteHandler::convert_to_sub_pred_v2(DeletePredicatePB* delete_pred, |
490 | 0 | TabletSchemaSPtr schema) { |
491 | 0 | if (!delete_pred->sub_predicates().empty() && delete_pred->sub_predicates_v2().empty()) { |
492 | 0 | for (const auto& condition_str : delete_pred->sub_predicates()) { |
493 | 0 | auto* sub_pred = delete_pred->add_sub_predicates_v2(); |
494 | 0 | auto condition = parse_condition(condition_str); |
495 | 0 | const auto& column = *DORIS_TRY(schema->column(condition.column_name)); |
496 | 0 | sub_pred->set_column_unique_id(column.unique_id()); |
497 | 0 | sub_pred->set_column_name(condition.column_name); |
498 | 0 | sub_pred->set_op(type_to_op_str(condition.condition_op)); |
499 | 0 | sub_pred->set_cond_value(condition.value_str.front()); |
500 | 0 | } |
501 | 0 | } |
502 | | |
503 | 0 | auto* in_pred_list = delete_pred->mutable_in_predicates(); |
504 | 0 | for (auto& in_pred : *in_pred_list) { |
505 | 0 | const auto& column = *DORIS_TRY(schema->column(in_pred.column_name())); |
506 | 0 | in_pred.set_column_unique_id(column.unique_id()); |
507 | 0 | } |
508 | 0 | return Status::OK(); |
509 | 0 | } |
510 | | |
511 | | bool DeleteHandler::is_condition_value_valid(const TabletColumn& column, |
512 | | const std::string& condition_op, |
513 | 140 | const string& value_str) { |
514 | 140 | if ("IS" == condition_op && ("NULL" == value_str || "NOT NULL" == value_str)) { |
515 | 2 | return true; |
516 | 2 | } |
517 | | |
518 | 138 | FieldType field_type = column.type(); |
519 | 138 | switch (field_type) { |
520 | 11 | case FieldType::OLAP_FIELD_TYPE_TINYINT: |
521 | 11 | return valid_signed_number<int8_t>(value_str); |
522 | 13 | case FieldType::OLAP_FIELD_TYPE_SMALLINT: |
523 | 13 | return valid_signed_number<int16_t>(value_str); |
524 | 54 | case FieldType::OLAP_FIELD_TYPE_INT: |
525 | 54 | return valid_signed_number<int32_t>(value_str); |
526 | 5 | case FieldType::OLAP_FIELD_TYPE_BIGINT: |
527 | 5 | return valid_signed_number<int64_t>(value_str); |
528 | 4 | case FieldType::OLAP_FIELD_TYPE_LARGEINT: |
529 | 4 | return valid_signed_number<int128_t>(value_str); |
530 | 0 | case FieldType::OLAP_FIELD_TYPE_UNSIGNED_TINYINT: |
531 | 0 | return valid_unsigned_number<uint8_t>(value_str); |
532 | 0 | case FieldType::OLAP_FIELD_TYPE_UNSIGNED_SMALLINT: |
533 | 0 | return valid_unsigned_number<uint16_t>(value_str); |
534 | 0 | case FieldType::OLAP_FIELD_TYPE_UNSIGNED_INT: |
535 | 0 | return valid_unsigned_number<uint32_t>(value_str); |
536 | 0 | case FieldType::OLAP_FIELD_TYPE_UNSIGNED_BIGINT: |
537 | 0 | return valid_unsigned_number<uint64_t>(value_str); |
538 | 7 | case FieldType::OLAP_FIELD_TYPE_DECIMAL: |
539 | 7 | return valid_decimal(value_str, column.precision(), column.frac()); |
540 | 0 | case FieldType::OLAP_FIELD_TYPE_DECIMAL32: |
541 | 0 | return valid_decimal(value_str, column.precision(), column.frac()); |
542 | 0 | case FieldType::OLAP_FIELD_TYPE_DECIMAL64: |
543 | 0 | return valid_decimal(value_str, column.precision(), column.frac()); |
544 | 0 | case FieldType::OLAP_FIELD_TYPE_DECIMAL128I: |
545 | 0 | return valid_decimal(value_str, column.precision(), column.frac()); |
546 | 0 | case FieldType::OLAP_FIELD_TYPE_DECIMAL256: |
547 | 0 | return valid_decimal(value_str, column.precision(), column.frac()); |
548 | 3 | case FieldType::OLAP_FIELD_TYPE_CHAR: |
549 | 7 | case FieldType::OLAP_FIELD_TYPE_VARCHAR: |
550 | 7 | return value_str.size() <= column.length(); |
551 | 0 | case FieldType::OLAP_FIELD_TYPE_STRING: |
552 | 0 | return value_str.size() <= config::string_type_length_soft_limit_bytes; |
553 | 5 | case FieldType::OLAP_FIELD_TYPE_DATE: |
554 | 11 | case FieldType::OLAP_FIELD_TYPE_DATETIME: |
555 | 11 | case FieldType::OLAP_FIELD_TYPE_DATEV2: |
556 | 11 | case FieldType::OLAP_FIELD_TYPE_DATETIMEV2: |
557 | 24 | case FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ: |
558 | 24 | return valid_datetime(value_str, column.frac()); |
559 | 0 | case FieldType::OLAP_FIELD_TYPE_BOOL: |
560 | 0 | return valid_bool(value_str); |
561 | 5 | case FieldType::OLAP_FIELD_TYPE_IPV4: |
562 | 5 | return valid_ipv4(value_str); |
563 | 8 | case FieldType::OLAP_FIELD_TYPE_IPV6: |
564 | 8 | return valid_ipv6(value_str); |
565 | 0 | default: |
566 | 0 | LOG(WARNING) << "unknown field type. [type=" << int(field_type) << "]"; |
567 | 138 | } |
568 | 0 | return false; |
569 | 138 | } |
570 | | |
571 | 135 | Status DeleteHandler::check_condition_valid(const TabletSchema& schema, const TCondition& cond) { |
572 | | // Check whether the column exists |
573 | 135 | int32_t field_index = schema.field_index(cond.column_name); |
574 | 135 | if (field_index < 0) { |
575 | 1 | return Status::Error<ErrorCode::INVALID_ARGUMENT>("field is not existent. [field_index={}]", |
576 | 1 | field_index); |
577 | 1 | } |
578 | | |
579 | | // Delete condition should only applied on key columns or duplicate key table, and |
580 | | // the condition column type should not be float or double. |
581 | 134 | const TabletColumn& column = schema.column(field_index); |
582 | | |
583 | 134 | if (column.type() == FieldType::OLAP_FIELD_TYPE_DOUBLE || |
584 | 134 | column.type() == FieldType::OLAP_FIELD_TYPE_FLOAT) { |
585 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>("data type is float or double."); |
586 | 0 | } |
587 | | |
588 | | // Check operator and operands size are matched. |
589 | 134 | if ("*=" != cond.condition_op && "!*=" != cond.condition_op && |
590 | 134 | cond.condition_values.size() != 1) { |
591 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition value size. [size={}]", |
592 | 0 | cond.condition_values.size()); |
593 | 0 | } |
594 | | |
595 | | // Check each operand is valid |
596 | 140 | for (const auto& condition_value : cond.condition_values) { |
597 | 140 | if (!is_condition_value_valid(column, cond.condition_op, condition_value)) { |
598 | 29 | return Status::Error<ErrorCode::INVALID_ARGUMENT>("invalid condition value. [value={}]", |
599 | 29 | condition_value); |
600 | 29 | } |
601 | 140 | } |
602 | | |
603 | 105 | if (!cond.__isset.column_unique_id) { |
604 | 105 | LOG(WARNING) << "column=" << cond.column_name |
605 | 105 | << " in predicate does not have uid, table id=" << schema.table_id(); |
606 | | // TODO(tsy): make it fail here after FE forbidding hard-link-schema-change |
607 | 105 | return Status::OK(); |
608 | 105 | } |
609 | 0 | if (schema.field_index(cond.column_unique_id) == -1) { |
610 | 0 | const auto& err_msg = |
611 | 0 | fmt::format("column id does not exists in table={}, schema version={},", |
612 | 0 | schema.table_id(), schema.schema_version()); |
613 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>(err_msg); |
614 | 0 | } |
615 | 0 | if (!iequal(schema.column_by_uid(cond.column_unique_id).name(), cond.column_name)) { |
616 | 0 | const auto& err_msg = fmt::format( |
617 | 0 | "colum name={} does not belongs to column uid={}, which " |
618 | 0 | "column name={}, " |
619 | 0 | "delete_cond.column_name ={}", |
620 | 0 | cond.column_name, cond.column_unique_id, |
621 | 0 | schema.column_by_uid(cond.column_unique_id).name(), cond.column_name); |
622 | 0 | return Status::Error<ErrorCode::INVALID_ARGUMENT>(err_msg); |
623 | 0 | } |
624 | | |
625 | 0 | return Status::OK(); |
626 | 0 | } |
627 | | |
628 | | PredicateType DeleteHandler::parse_condition_op(const std::string& op_str, |
629 | 302 | const std::list<std::string>& cond_values) { |
630 | 302 | if (trim(to_lower(op_str)) == "=") { |
631 | 92 | return PredicateType::EQ; |
632 | 210 | } else if (trim(to_lower(op_str)) == "!=") { |
633 | 18 | return PredicateType::NE; |
634 | 192 | } else if (trim(to_lower(op_str)) == ">>") { |
635 | 9 | return PredicateType::GT; |
636 | 183 | } else if (trim(to_lower(op_str)) == "<<") { |
637 | 129 | return PredicateType::LT; |
638 | 129 | } else if (trim(to_lower(op_str)) == ">=") { |
639 | 5 | return PredicateType::GE; |
640 | 49 | } else if (trim(to_lower(op_str)) == "<=") { |
641 | 7 | return PredicateType::LE; |
642 | 42 | } else if (trim(to_lower(op_str)) == "*=") { |
643 | 0 | return cond_values.size() > 1 ? PredicateType::IN_LIST : PredicateType::EQ; |
644 | 42 | } else if (trim(to_lower(op_str)) == "!*=") { |
645 | 0 | return cond_values.size() > 1 ? PredicateType::NOT_IN_LIST : PredicateType::NE; |
646 | 42 | } else if (trim(to_lower(op_str)) == "is") { |
647 | 42 | return to_lower(cond_values.front()) == "null" ? PredicateType::IS_NULL |
648 | 42 | : PredicateType::IS_NOT_NULL; |
649 | 42 | } else { |
650 | 0 | throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>( |
651 | 0 | "invalid condition operator. operator={}", op_str)); |
652 | 0 | } |
653 | 0 | return PredicateType::UNKNOWN; |
654 | 302 | } |
655 | | |
656 | | DeleteHandler::ConditionParseResult DeleteHandler::parse_condition( |
657 | 100 | const DeleteSubPredicatePB& sub_cond) { |
658 | 100 | ConditionParseResult res; |
659 | 100 | if (!sub_cond.has_column_name() || !sub_cond.has_op() || !sub_cond.has_cond_value()) { |
660 | 0 | throw Exception(Status::Error<ErrorCode::INVALID_ARGUMENT>( |
661 | 0 | "fail to parse condition. condition={} {} {}", sub_cond.column_name(), |
662 | 0 | sub_cond.op(), sub_cond.cond_value())); |
663 | 0 | } |
664 | 100 | if (sub_cond.has_column_unique_id()) { |
665 | 0 | res.col_unique_id = sub_cond.column_unique_id(); |
666 | 0 | } |
667 | 100 | res.column_name = sub_cond.column_name(); |
668 | 100 | res.value_str.push_back(sub_cond.cond_value()); |
669 | 100 | res.condition_op = parse_condition_op(sub_cond.op(), res.value_str); |
670 | 100 | return res; |
671 | 100 | } |
672 | | |
673 | | // clang-format off |
674 | | // Condition string format, the format is (column_name)(op)(value) |
675 | | // eg: condition_str="c1 = 1597751948193618247 and length(source)<1;\n;\n" |
676 | | // column_name: matches "c1", must include FeNameFormat.java COLUMN_NAME_REGEX |
677 | | // and compactible with any the lagacy |
678 | | // operator: matches "=" |
679 | | // value: matches "1597751948193618247 and length(source)<1;\n;\n" |
680 | | // |
681 | | // For more info, see DeleteHandler::construct_sub_predicates |
682 | | // FIXME(gavin): This is a tricky implementation, it should not be the final resolution, refactor it. |
683 | | const char* const CONDITION_STR_PATTERN = |
684 | | // .----------------- column-name --------------------------. .----------------------- operator ------------------------. .------------ value ----------. |
685 | | R"(([_a-zA-Z@0-9\s/\p{L}][.a-zA-Z0-9_+-/?@#$%^&*"\s,:\p{L}]*)\s*((?:=)|(?:!=)|(?:>>)|(?:<<)|(?:>=)|(?:<=)|(?:\*=)|(?: IS ))\s*('((?:[\s\S]+)?)'|(?:[\s\S]+)?))"; |
686 | | // '----------------- group 1 ------------------------------' '--------------------- group 2 ---------------------------' | '-- group 4--' | |
687 | | // match any of: = != >> << >= <= *= " IS " '----------- group 3 ---------' |
688 | | // match **ANY THING** without(4) |
689 | | // or with(3) single quote |
690 | | // clang-format on |
691 | | RE2 DELETE_HANDLER_REGEX(CONDITION_STR_PATTERN); |
692 | | |
693 | | DeleteHandler::ConditionParseResult DeleteHandler::parse_condition( |
694 | 182 | const std::string& condition_str) { |
695 | 182 | ConditionParseResult res; |
696 | 182 | std::string col_name, op, value, g4; |
697 | | |
698 | 182 | bool matched = RE2::FullMatch(condition_str, DELETE_HANDLER_REGEX, &col_name, &op, &value, |
699 | 182 | &g4); // exact match |
700 | | |
701 | 182 | if (!matched) { |
702 | 0 | throw Exception( |
703 | 0 | Status::InvalidArgument("fail to sub condition. condition={}", condition_str)); |
704 | 0 | } |
705 | | |
706 | 182 | res.column_name = col_name; |
707 | | |
708 | | // match string with single quotes, a = b or a = 'b' |
709 | 182 | if (!g4.empty()) { |
710 | 141 | res.value_str.push_back(g4); |
711 | 141 | } else { |
712 | 41 | res.value_str.push_back(value); |
713 | 41 | } |
714 | 182 | res.condition_op = DeleteHandler::parse_condition_op(op, res.value_str); |
715 | 182 | VLOG_NOTICE << "parsed condition_str: col_name={" << col_name << "} op={" << op << "} val={" |
716 | 50 | << res.value_str.back() << "}"; |
717 | 182 | return res; |
718 | 182 | } |
719 | | |
720 | | template <typename SubPredType> |
721 | | requires(std::is_same_v<SubPredType, DeleteSubPredicatePB> or |
722 | | std::is_same_v<SubPredType, std::string>) |
723 | | Status DeleteHandler::_parse_column_pred(TabletSchemaSPtr complete_schema, |
724 | | TabletSchemaSPtr delete_pred_related_schema, |
725 | | const RepeatedPtrField<SubPredType>& sub_pred_list, |
726 | 169 | DeleteConditions* delete_conditions) { |
727 | 181 | for (const auto& sub_predicate : sub_pred_list) { |
728 | 181 | auto condition = parse_condition(sub_predicate); |
729 | 181 | int32_t col_unique_id = -1; |
730 | 181 | if constexpr (std::is_same_v<SubPredType, DeleteSubPredicatePB>) { |
731 | 100 | if (sub_predicate.has_column_unique_id()) [[likely]] { |
732 | 0 | col_unique_id = sub_predicate.column_unique_id(); |
733 | 0 | } |
734 | 100 | } |
735 | 181 | if (col_unique_id < 0) { |
736 | 181 | const auto& column = |
737 | 181 | *DORIS_TRY(delete_pred_related_schema->column(condition.column_name)); |
738 | 181 | col_unique_id = column.unique_id(); |
739 | 181 | } |
740 | 181 | condition.col_unique_id = col_unique_id; |
741 | 181 | const auto& column = complete_schema->column_by_uid(col_unique_id); |
742 | 181 | uint32_t index = complete_schema->field_index(col_unique_id); |
743 | 181 | std::shared_ptr<ColumnPredicate> predicate; |
744 | 181 | RETURN_IF_ERROR(parse_to_predicate(index, column.get_vec_type(), condition, |
745 | 181 | _predicate_arena, predicate)); |
746 | 174 | if (predicate != nullptr) { |
747 | 174 | delete_conditions->column_predicate_vec.push_back(predicate); |
748 | 174 | } |
749 | 174 | } |
750 | 162 | return Status::OK(); |
751 | 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 | 726 | 87 | DeleteConditions* delete_conditions) { | 727 | 100 | for (const auto& sub_predicate : sub_pred_list) { | 728 | 100 | auto condition = parse_condition(sub_predicate); | 729 | 100 | int32_t col_unique_id = -1; | 730 | 100 | if constexpr (std::is_same_v<SubPredType, DeleteSubPredicatePB>) { | 731 | 100 | if (sub_predicate.has_column_unique_id()) [[likely]] { | 732 | 0 | col_unique_id = sub_predicate.column_unique_id(); | 733 | 0 | } | 734 | 100 | } | 735 | 100 | if (col_unique_id < 0) { | 736 | 100 | const auto& column = | 737 | 100 | *DORIS_TRY(delete_pred_related_schema->column(condition.column_name)); | 738 | 100 | col_unique_id = column.unique_id(); | 739 | 100 | } | 740 | 100 | condition.col_unique_id = col_unique_id; | 741 | 100 | const auto& column = complete_schema->column_by_uid(col_unique_id); | 742 | 100 | uint32_t index = complete_schema->field_index(col_unique_id); | 743 | 100 | std::shared_ptr<ColumnPredicate> predicate; | 744 | 100 | RETURN_IF_ERROR(parse_to_predicate(index, column.get_vec_type(), condition, | 745 | 100 | _predicate_arena, predicate)); | 746 | 100 | if (predicate != nullptr) { | 747 | 100 | delete_conditions->column_predicate_vec.push_back(predicate); | 748 | 100 | } | 749 | 100 | } | 750 | 87 | return Status::OK(); | 751 | 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 | 726 | 82 | DeleteConditions* delete_conditions) { | 727 | 82 | for (const auto& sub_predicate : sub_pred_list) { | 728 | 81 | auto condition = parse_condition(sub_predicate); | 729 | 81 | int32_t col_unique_id = -1; | 730 | | if constexpr (std::is_same_v<SubPredType, DeleteSubPredicatePB>) { | 731 | | if (sub_predicate.has_column_unique_id()) [[likely]] { | 732 | | col_unique_id = sub_predicate.column_unique_id(); | 733 | | } | 734 | | } | 735 | 81 | if (col_unique_id < 0) { | 736 | 81 | const auto& column = | 737 | 81 | *DORIS_TRY(delete_pred_related_schema->column(condition.column_name)); | 738 | 81 | col_unique_id = column.unique_id(); | 739 | 81 | } | 740 | 81 | condition.col_unique_id = col_unique_id; | 741 | 81 | const auto& column = complete_schema->column_by_uid(col_unique_id); | 742 | 81 | uint32_t index = complete_schema->field_index(col_unique_id); | 743 | 81 | std::shared_ptr<ColumnPredicate> predicate; | 744 | 81 | RETURN_IF_ERROR(parse_to_predicate(index, column.get_vec_type(), condition, | 745 | 81 | _predicate_arena, predicate)); | 746 | 74 | if (predicate != nullptr) { | 747 | 74 | delete_conditions->column_predicate_vec.push_back(predicate); | 748 | 74 | } | 749 | 74 | } | 750 | 75 | return Status::OK(); | 751 | 82 | } |
|
752 | | |
753 | | Status DeleteHandler::init(TabletSchemaSPtr tablet_schema, |
754 | 371 | const std::vector<RowsetMetaSharedPtr>& delete_preds, int64_t version) { |
755 | 371 | DCHECK(!_is_inited) << "reinitialize delete handler."; |
756 | 371 | DCHECK(version >= 0) << "invalid parameters. version=" << version; |
757 | | |
758 | 371 | for (const auto& delete_pred : delete_preds) { |
759 | | // Skip the delete condition with large version |
760 | 169 | if (delete_pred->version().first > version) { |
761 | 0 | continue; |
762 | 0 | } |
763 | | // Need the tablet schema at the delete condition to parse the accurate column |
764 | 169 | const auto& delete_pred_related_schema = delete_pred->tablet_schema(); |
765 | 169 | const auto& delete_condition = delete_pred->delete_predicate(); |
766 | 169 | DeleteConditions temp; |
767 | 169 | temp.filter_version = delete_pred->version().first; |
768 | 169 | if (!delete_condition.sub_predicates_v2().empty()) { |
769 | 87 | RETURN_IF_ERROR(_parse_column_pred(tablet_schema, delete_pred_related_schema, |
770 | 87 | delete_condition.sub_predicates_v2(), &temp)); |
771 | 87 | } else { |
772 | | // make it compatible with the former versions |
773 | 82 | RETURN_IF_ERROR(_parse_column_pred(tablet_schema, delete_pred_related_schema, |
774 | 82 | delete_condition.sub_predicates(), &temp)); |
775 | 82 | } |
776 | 162 | for (const auto& in_predicate : delete_condition.in_predicates()) { |
777 | 2 | ConditionParseResult condition; |
778 | 2 | condition.column_name = in_predicate.column_name(); |
779 | | |
780 | 2 | int32_t col_unique_id = -1; |
781 | 2 | if (in_predicate.has_column_unique_id()) { |
782 | 0 | col_unique_id = in_predicate.column_unique_id(); |
783 | 2 | } else { |
784 | | // if upgrade from version 2.0.x, column_unique_id maybe not set |
785 | 2 | const auto& pre_column = |
786 | 2 | *DORIS_TRY(delete_pred_related_schema->column(condition.column_name)); |
787 | 2 | col_unique_id = pre_column.unique_id(); |
788 | 2 | } |
789 | 2 | if (col_unique_id == -1) { |
790 | 0 | return Status::Error<ErrorCode::DELETE_INVALID_CONDITION>( |
791 | 0 | "cannot get column_unique_id for column {}", condition.column_name); |
792 | 0 | } |
793 | 2 | condition.col_unique_id = col_unique_id; |
794 | | |
795 | 2 | condition.condition_op = |
796 | 2 | in_predicate.is_not_in() ? PredicateType::NOT_IN_LIST : PredicateType::IN_LIST; |
797 | 5 | for (const auto& value : in_predicate.values()) { |
798 | 5 | condition.value_str.push_back(value); |
799 | 5 | } |
800 | 2 | const auto& column = tablet_schema->column_by_uid(col_unique_id); |
801 | 2 | uint32_t index = tablet_schema->field_index(col_unique_id); |
802 | 2 | std::shared_ptr<ColumnPredicate> predicate; |
803 | 2 | RETURN_IF_ERROR(parse_to_in_predicate(index, column.get_vec_type(), condition, |
804 | 2 | _predicate_arena, predicate)); |
805 | 2 | temp.column_predicate_vec.push_back(predicate); |
806 | 2 | } |
807 | | |
808 | 162 | _del_conds.emplace_back(std::move(temp)); |
809 | 162 | } |
810 | | |
811 | 364 | _is_inited = true; |
812 | | |
813 | 364 | return Status::OK(); |
814 | 371 | } |
815 | | |
816 | 388 | DeleteHandler::~DeleteHandler() { |
817 | 388 | if (!_is_inited) { |
818 | 24 | return; |
819 | 24 | } |
820 | | |
821 | 364 | _del_conds.clear(); |
822 | 364 | _is_inited = false; |
823 | 364 | } |
824 | | |
825 | | void DeleteHandler::get_delete_conditions_after_version( |
826 | | int64_t version, AndBlockColumnPredicate* and_block_column_predicate_ptr, |
827 | | std::unordered_map<int32_t, std::vector<std::shared_ptr<const ColumnPredicate>>>* |
828 | 1.07k | del_predicates_for_zone_map) const { |
829 | 1.07k | for (const auto& del_cond : _del_conds) { |
830 | 555 | if (del_cond.filter_version > version) { |
831 | | // now, only query support delete column predicate operator |
832 | 406 | if (!del_cond.column_predicate_vec.empty()) { |
833 | 406 | if (del_cond.column_predicate_vec.size() == 1) { |
834 | 406 | auto single_column_block_predicate = SingleColumnBlockPredicate::create_unique( |
835 | 406 | del_cond.column_predicate_vec[0]); |
836 | 406 | and_block_column_predicate_ptr->add_column_predicate( |
837 | 406 | std::move(single_column_block_predicate)); |
838 | 406 | if (del_predicates_for_zone_map->count( |
839 | 406 | del_cond.column_predicate_vec[0]->column_id()) < 1) { |
840 | 406 | del_predicates_for_zone_map->insert( |
841 | 406 | {del_cond.column_predicate_vec[0]->column_id(), |
842 | 406 | std::vector<std::shared_ptr<const ColumnPredicate>> {}}); |
843 | 406 | } |
844 | 406 | (*del_predicates_for_zone_map)[del_cond.column_predicate_vec[0]->column_id()] |
845 | 406 | .push_back(del_cond.column_predicate_vec[0]); |
846 | 406 | } else { |
847 | 0 | auto or_column_predicate = OrBlockColumnPredicate::create_unique(); |
848 | | |
849 | | // build or_column_predicate |
850 | | // when delete from where a = 1 and b = 2, we can not use del_predicates_for_zone_map to filter zone page, |
851 | | // so here do not put predicate to del_predicates_for_zone_map, |
852 | | // refer #17145 for more details. |
853 | | // // TODO: need refactor design and code to use more version delete and more column delete to filter zone page. |
854 | 0 | std::for_each(del_cond.column_predicate_vec.cbegin(), |
855 | 0 | del_cond.column_predicate_vec.cend(), |
856 | 0 | [&or_column_predicate]( |
857 | 0 | const std::shared_ptr<const ColumnPredicate> predicate) { |
858 | 0 | or_column_predicate->add_column_predicate( |
859 | 0 | SingleColumnBlockPredicate::create_unique(predicate)); |
860 | 0 | }); |
861 | 0 | and_block_column_predicate_ptr->add_column_predicate( |
862 | 0 | std::move(or_column_predicate)); |
863 | 0 | } |
864 | 406 | } |
865 | 406 | } |
866 | 555 | } |
867 | 1.07k | } |
868 | | |
869 | | } // namespace doris |