be/src/runtime/descriptors.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 | | // This file is copied from |
18 | | // https://github.com/apache/impala/blob/branch-2.9.0/be/src/runtime/descriptors.cc |
19 | | // and modified by Doris |
20 | | |
21 | | #include "runtime/descriptors.h" |
22 | | |
23 | | #include <fmt/format.h> |
24 | | #include <gen_cpp/Descriptors_types.h> |
25 | | #include <gen_cpp/Types_types.h> |
26 | | #include <gen_cpp/descriptors.pb.h> |
27 | | #include <stddef.h> |
28 | | #include <thrift/protocol/TDebugProtocol.h> |
29 | | |
30 | | #include <algorithm> |
31 | | #include <boost/algorithm/string/join.hpp> |
32 | | |
33 | | #include "common/exception.h" |
34 | | #include "common/object_pool.h" |
35 | | #include "core/column/column_nothing.h" |
36 | | #include "core/data_type/data_type_array.h" |
37 | | #include "core/data_type/data_type_decimal.h" |
38 | | #include "core/data_type/data_type_factory.hpp" |
39 | | #include "core/data_type/data_type_map.h" |
40 | | #include "core/data_type/data_type_struct.h" |
41 | | #include "core/types.h" |
42 | | #include "exec/common/util.hpp" |
43 | | #include "exprs/aggregate/aggregate_function.h" |
44 | | #include "exprs/function/function_helpers.h" |
45 | | #include "exprs/vexpr.h" |
46 | | #include "util/string_util.h" |
47 | | |
48 | | namespace doris { |
49 | | const int RowDescriptor::INVALID_IDX = -1; |
50 | | |
51 | | SlotDescriptor::SlotDescriptor(const TSlotDescriptor& tdesc) |
52 | 8.27M | : _id(tdesc.id), |
53 | 8.27M | _type(DataTypeFactory::instance().create_data_type(tdesc.slotType, |
54 | 8.27M | tdesc.nullIndicatorBit != -1)), |
55 | 8.27M | _parent(tdesc.parent), |
56 | 8.27M | _col_pos(tdesc.columnPos), |
57 | 8.27M | _col_name(tdesc.colName), |
58 | 8.27M | _col_name_lower_case(to_lower(tdesc.colName)), |
59 | 8.27M | _col_unique_id(tdesc.col_unique_id), |
60 | 8.27M | _slot_idx(tdesc.slotIdx), |
61 | 8.27M | _field_idx(-1), |
62 | 8.27M | _is_key(tdesc.is_key), |
63 | 8.27M | _column_paths(tdesc.column_paths), |
64 | 8.27M | _all_access_paths(tdesc.__isset.all_access_paths ? tdesc.all_access_paths |
65 | 8.27M | : TColumnAccessPaths {}), |
66 | 8.27M | _predicate_access_paths(tdesc.__isset.predicate_access_paths |
67 | 8.27M | ? tdesc.predicate_access_paths |
68 | 8.27M | : TColumnAccessPaths {}), |
69 | 18.4E | _is_auto_increment(tdesc.__isset.is_auto_increment ? tdesc.is_auto_increment : false), |
70 | 8.27M | _col_default_value(tdesc.__isset.col_default_value ? tdesc.col_default_value : "") { |
71 | 8.27M | if (tdesc.__isset.virtual_column_expr) { |
72 | | // Make sure virtual column is valid. |
73 | 356 | if (tdesc.virtual_column_expr.nodes.empty()) { |
74 | 2 | throw doris::Exception(doris::ErrorCode::FATAL_ERROR, |
75 | 2 | "Virtual column expr node is empty, col_name: {}, " |
76 | 2 | "col_unique_id: {}", |
77 | 2 | tdesc.colName, tdesc.col_unique_id); |
78 | 2 | } |
79 | 354 | const auto& node = tdesc.virtual_column_expr.nodes[0]; |
80 | 354 | if (node.node_type == TExprNodeType::SLOT_REF) { |
81 | 2 | throw doris::Exception(doris::ErrorCode::FATAL_ERROR, |
82 | 2 | "Virtual column expr node is slot ref, col_name: {}, " |
83 | 2 | "col_unique_id: {}", |
84 | 2 | tdesc.colName, tdesc.col_unique_id); |
85 | 2 | } |
86 | 352 | this->virtual_column_expr = std::make_shared<doris::TExpr>(tdesc.virtual_column_expr); |
87 | 352 | } |
88 | 8.27M | } |
89 | | |
90 | | SlotDescriptor::SlotDescriptor(const PSlotDescriptor& pdesc) |
91 | 268k | : _id(pdesc.id()), |
92 | 268k | _type(DataTypeFactory::instance().create_data_type(pdesc.slot_type(), |
93 | 268k | pdesc.null_indicator_bit() != -1)), |
94 | 268k | _parent(pdesc.parent()), |
95 | 268k | _col_pos(pdesc.column_pos()), |
96 | 268k | _col_name(pdesc.col_name()), |
97 | 268k | _col_name_lower_case(to_lower(pdesc.col_name())), |
98 | 268k | _col_unique_id(pdesc.col_unique_id()), |
99 | 268k | _slot_idx(pdesc.slot_idx()), |
100 | 268k | _field_idx(-1), |
101 | 268k | _is_key(pdesc.is_key()), |
102 | 268k | _column_paths(pdesc.column_paths().begin(), pdesc.column_paths().end()), |
103 | 268k | _is_auto_increment(pdesc.is_auto_increment()) { |
104 | 268k | auto convert_to_thrift_column_access_path = [](const PColumnAccessPath& pb_path) { |
105 | 3 | TColumnAccessPath thrift_path; |
106 | 3 | thrift_path.type = (TAccessPathType::type)pb_path.type(); |
107 | 3 | if (pb_path.has_data_access_path()) { |
108 | 3 | thrift_path.__isset.data_access_path = true; |
109 | 6 | for (int i = 0; i < pb_path.data_access_path().path_size(); ++i) { |
110 | 3 | thrift_path.data_access_path.path.push_back(pb_path.data_access_path().path(i)); |
111 | 3 | } |
112 | 3 | } |
113 | 3 | if (pb_path.has_meta_access_path()) { |
114 | 0 | thrift_path.__isset.meta_access_path = true; |
115 | 0 | for (int i = 0; i < pb_path.meta_access_path().path_size(); ++i) { |
116 | 0 | thrift_path.meta_access_path.path.push_back(pb_path.meta_access_path().path(i)); |
117 | 0 | } |
118 | 0 | } |
119 | 3 | return thrift_path; |
120 | 3 | }; |
121 | 268k | for (const auto& pb_path : pdesc.all_access_paths()) { |
122 | 3 | _all_access_paths.push_back(convert_to_thrift_column_access_path(pb_path)); |
123 | 3 | } |
124 | 268k | for (const auto& pb_path : pdesc.predicate_access_paths()) { |
125 | 0 | _predicate_access_paths.push_back(convert_to_thrift_column_access_path(pb_path)); |
126 | 0 | } |
127 | 268k | } |
128 | | |
129 | | #ifdef BE_TEST |
130 | | SlotDescriptor::SlotDescriptor() |
131 | | : _id(0), |
132 | | _type(nullptr), |
133 | | _parent(0), |
134 | | _col_pos(0), |
135 | | _col_unique_id(0), |
136 | | _slot_idx(0), |
137 | | _field_idx(-1), |
138 | | _is_key(false), |
139 | | _is_auto_increment(false) {} |
140 | | #endif |
141 | | |
142 | 359k | void SlotDescriptor::to_protobuf(PSlotDescriptor* pslot) const { |
143 | 359k | pslot->set_id(_id); |
144 | 359k | pslot->set_parent(_parent); |
145 | 359k | _type->to_protobuf(pslot->mutable_slot_type()); |
146 | 359k | pslot->set_column_pos(_col_pos); |
147 | 359k | pslot->set_byte_offset(0); |
148 | 359k | pslot->set_null_indicator_byte(0); |
149 | 359k | pslot->set_null_indicator_bit(_type->is_nullable() ? 0 : -1); |
150 | 359k | pslot->set_col_name(_col_name); |
151 | 359k | pslot->set_slot_idx(_slot_idx); |
152 | 359k | pslot->set_col_unique_id(_col_unique_id); |
153 | 359k | pslot->set_is_key(_is_key); |
154 | 359k | pslot->set_is_auto_increment(_is_auto_increment); |
155 | 359k | pslot->set_col_type(_type->get_primitive_type()); |
156 | 359k | for (const std::string& path : _column_paths) { |
157 | 69 | pslot->add_column_paths(path); |
158 | 69 | } |
159 | 359k | auto convert_to_protobuf_column_access_path = [](const TColumnAccessPath& thrift_path, |
160 | 359k | doris::PColumnAccessPath* pb_path) { |
161 | 3 | pb_path->Clear(); |
162 | 3 | pb_path->set_type((PAccessPathType)thrift_path.type); // 使用 reinterpret_cast 进行类型转换 |
163 | 3 | if (thrift_path.__isset.data_access_path) { |
164 | 3 | auto* pb_data = pb_path->mutable_data_access_path(); |
165 | 3 | pb_data->Clear(); |
166 | 3 | for (const auto& s : thrift_path.data_access_path.path) { |
167 | 3 | pb_data->add_path(s); |
168 | 3 | } |
169 | 3 | } |
170 | 3 | if (thrift_path.__isset.meta_access_path) { |
171 | 0 | auto* pb_meta = pb_path->mutable_meta_access_path(); |
172 | 0 | pb_meta->Clear(); |
173 | 0 | for (const auto& s : thrift_path.meta_access_path.path) { |
174 | 0 | pb_meta->add_path(s); |
175 | 0 | } |
176 | 0 | } |
177 | 3 | }; |
178 | 359k | for (const auto& path : _all_access_paths) { |
179 | 3 | auto* pb_path = pslot->add_all_access_paths(); |
180 | 3 | convert_to_protobuf_column_access_path(path, pb_path); |
181 | 3 | } |
182 | 359k | for (const auto& path : _predicate_access_paths) { |
183 | 0 | auto* pb_path = pslot->add_predicate_access_paths(); |
184 | 0 | convert_to_protobuf_column_access_path(path, pb_path); |
185 | 0 | } |
186 | 359k | } |
187 | | |
188 | 17.1M | DataTypePtr SlotDescriptor::get_data_type_ptr() const { |
189 | 17.1M | return get_data_type_with_default_argument(type()); |
190 | 17.1M | } |
191 | | |
192 | 12.0M | MutableColumnPtr SlotDescriptor::get_empty_mutable_column() const { |
193 | 12.0M | if (this->get_virtual_column_expr() != nullptr) { |
194 | 465 | return ColumnNothing::create(0); |
195 | 465 | } |
196 | | |
197 | 12.0M | return type()->create_column(); |
198 | 12.0M | } |
199 | | |
200 | 26.0M | bool SlotDescriptor::is_nullable() const { |
201 | 26.0M | return _type->is_nullable(); |
202 | 26.0M | } |
203 | | |
204 | 824k | PrimitiveType SlotDescriptor::col_type() const { |
205 | 824k | return _type->get_primitive_type(); |
206 | 824k | } |
207 | | |
208 | 8 | std::string SlotDescriptor::debug_string() const { |
209 | 8 | const bool is_virtual = this->get_virtual_column_expr() != nullptr; |
210 | 8 | return fmt::format( |
211 | 8 | "SlotDescriptor(id={}, type={}, col_name={}, col_unique_id={}, " |
212 | 8 | "is_virtual={})", |
213 | 8 | _id, _type->get_name(), _col_name, _col_unique_id, is_virtual); |
214 | 8 | } |
215 | | |
216 | | TableDescriptor::TableDescriptor(const TTableDescriptor& tdesc) |
217 | 376k | : _table_type(tdesc.tableType), |
218 | 376k | _name(tdesc.tableName), |
219 | 376k | _database(tdesc.dbName), |
220 | 376k | _table_id(tdesc.id), |
221 | 376k | _num_cols(tdesc.numCols), |
222 | 376k | _num_clustering_cols(tdesc.numClusteringCols) {} |
223 | | |
224 | 0 | std::string TableDescriptor::debug_string() const { |
225 | 0 | std::stringstream out; |
226 | 0 | out << "#cols=" << _num_cols << " #clustering_cols=" << _num_clustering_cols; |
227 | 0 | return out.str(); |
228 | 0 | } |
229 | | |
230 | 373k | OlapTableDescriptor::OlapTableDescriptor(const TTableDescriptor& tdesc) : TableDescriptor(tdesc) {} |
231 | | |
232 | 0 | std::string OlapTableDescriptor::debug_string() const { |
233 | 0 | std::stringstream out; |
234 | 0 | out << "OlapTable(" << TableDescriptor::debug_string() << ")"; |
235 | 0 | return out.str(); |
236 | 0 | } |
237 | | |
238 | | DictionaryTableDescriptor::DictionaryTableDescriptor(const TTableDescriptor& tdesc) |
239 | 0 | : TableDescriptor(tdesc) {} |
240 | | |
241 | 0 | std::string DictionaryTableDescriptor::debug_string() const { |
242 | 0 | std::stringstream out; |
243 | 0 | out << "Dictionary(" << TableDescriptor::debug_string() << ")"; |
244 | 0 | return out.str(); |
245 | 0 | } |
246 | | |
247 | | SchemaTableDescriptor::SchemaTableDescriptor(const TTableDescriptor& tdesc) |
248 | 3.04k | : TableDescriptor(tdesc), _schema_table_type(tdesc.schemaTable.tableType) {} |
249 | 3.04k | SchemaTableDescriptor::~SchemaTableDescriptor() = default; |
250 | | |
251 | 0 | std::string SchemaTableDescriptor::debug_string() const { |
252 | 0 | std::stringstream out; |
253 | 0 | out << "SchemaTable(" << TableDescriptor::debug_string() << ")"; |
254 | 0 | return out.str(); |
255 | 0 | } |
256 | | |
257 | | BrokerTableDescriptor::BrokerTableDescriptor(const TTableDescriptor& tdesc) |
258 | 0 | : TableDescriptor(tdesc) {} |
259 | | |
260 | 0 | BrokerTableDescriptor::~BrokerTableDescriptor() = default; |
261 | | |
262 | 0 | std::string BrokerTableDescriptor::debug_string() const { |
263 | 0 | std::stringstream out; |
264 | 0 | out << "BrokerTable(" << TableDescriptor::debug_string() << ")"; |
265 | 0 | return out.str(); |
266 | 0 | } |
267 | | |
268 | 36 | HiveTableDescriptor::HiveTableDescriptor(const TTableDescriptor& tdesc) : TableDescriptor(tdesc) {} |
269 | | |
270 | 36 | HiveTableDescriptor::~HiveTableDescriptor() = default; |
271 | | |
272 | 0 | std::string HiveTableDescriptor::debug_string() const { |
273 | 0 | std::stringstream out; |
274 | 0 | out << "HiveTable(" << TableDescriptor::debug_string() << ")"; |
275 | 0 | return out.str(); |
276 | 0 | } |
277 | | |
278 | | IcebergTableDescriptor::IcebergTableDescriptor(const TTableDescriptor& tdesc) |
279 | 0 | : TableDescriptor(tdesc) {} |
280 | | |
281 | 0 | IcebergTableDescriptor::~IcebergTableDescriptor() = default; |
282 | | |
283 | 0 | std::string IcebergTableDescriptor::debug_string() const { |
284 | 0 | std::stringstream out; |
285 | 0 | out << "IcebergTable(" << TableDescriptor::debug_string() << ")"; |
286 | 0 | return out.str(); |
287 | 0 | } |
288 | | |
289 | | MaxComputeTableDescriptor::MaxComputeTableDescriptor(const TTableDescriptor& tdesc) |
290 | 0 | : TableDescriptor(tdesc), |
291 | 0 | _region(tdesc.mcTable.region), |
292 | 0 | _project(tdesc.mcTable.project), |
293 | 0 | _table(tdesc.mcTable.table), |
294 | 0 | _odps_url(tdesc.mcTable.odps_url), |
295 | 0 | _tunnel_url(tdesc.mcTable.tunnel_url), |
296 | 0 | _access_key(tdesc.mcTable.access_key), |
297 | 0 | _secret_key(tdesc.mcTable.secret_key), |
298 | 0 | _public_access(tdesc.mcTable.public_access) { |
299 | 0 | if (tdesc.mcTable.__isset.endpoint) { |
300 | 0 | _endpoint = tdesc.mcTable.endpoint; |
301 | 0 | } else { |
302 | 0 | _init_status = Status::InvalidArgument( |
303 | 0 | "fail to init MaxComputeTableDescriptor, missing endpoint."); |
304 | 0 | } |
305 | |
|
306 | 0 | if (tdesc.mcTable.__isset.quota) { |
307 | 0 | _quota = tdesc.mcTable.quota; |
308 | 0 | } else { |
309 | 0 | _init_status = |
310 | 0 | Status::InvalidArgument("fail to init MaxComputeTableDescriptor, missing quota."); |
311 | 0 | } |
312 | |
|
313 | 0 | if (tdesc.mcTable.__isset.properties) [[likely]] { |
314 | 0 | _props = tdesc.mcTable.properties; |
315 | 0 | } else { |
316 | 0 | static const std::string MC_ACCESS_KEY = "mc.access_key"; |
317 | 0 | static const std::string MC_SECRET_KEY = "mc.secret_key"; |
318 | 0 | _props.insert({MC_ACCESS_KEY, _access_key}); |
319 | 0 | _props.insert({MC_SECRET_KEY, _secret_key}); |
320 | 0 | } |
321 | 0 | } |
322 | | |
323 | 0 | MaxComputeTableDescriptor::~MaxComputeTableDescriptor() = default; |
324 | | |
325 | 0 | std::string MaxComputeTableDescriptor::debug_string() const { |
326 | 0 | std::stringstream out; |
327 | 0 | out << "MaxComputeTable(" << TableDescriptor::debug_string() << ")"; |
328 | 0 | return out.str(); |
329 | 0 | } |
330 | | |
331 | | TrinoConnectorTableDescriptor::TrinoConnectorTableDescriptor(const TTableDescriptor& tdesc) |
332 | 0 | : TableDescriptor(tdesc) {} |
333 | | |
334 | 0 | TrinoConnectorTableDescriptor::~TrinoConnectorTableDescriptor() = default; |
335 | | |
336 | 0 | std::string TrinoConnectorTableDescriptor::debug_string() const { |
337 | 0 | std::stringstream out; |
338 | 0 | out << "TrinoConnectorTable(" << TableDescriptor::debug_string() << ")"; |
339 | 0 | return out.str(); |
340 | 0 | } |
341 | | |
342 | 0 | EsTableDescriptor::EsTableDescriptor(const TTableDescriptor& tdesc) : TableDescriptor(tdesc) {} |
343 | | |
344 | 0 | EsTableDescriptor::~EsTableDescriptor() = default; |
345 | | |
346 | 0 | std::string EsTableDescriptor::debug_string() const { |
347 | 0 | std::stringstream out; |
348 | 0 | out << "EsTable(" << TableDescriptor::debug_string() << ")"; |
349 | 0 | return out.str(); |
350 | 0 | } |
351 | | |
352 | | MySQLTableDescriptor::MySQLTableDescriptor(const TTableDescriptor& tdesc) |
353 | 85 | : TableDescriptor(tdesc), |
354 | 85 | _mysql_db(tdesc.mysqlTable.db), |
355 | 85 | _mysql_table(tdesc.mysqlTable.table), |
356 | 85 | _host(tdesc.mysqlTable.host), |
357 | 85 | _port(tdesc.mysqlTable.port), |
358 | 85 | _user(tdesc.mysqlTable.user), |
359 | 85 | _passwd(tdesc.mysqlTable.passwd), |
360 | 85 | _charset(tdesc.mysqlTable.charset) {} |
361 | | |
362 | 0 | std::string MySQLTableDescriptor::debug_string() const { |
363 | 0 | std::stringstream out; |
364 | 0 | out << "MySQLTable(" << TableDescriptor::debug_string() << " _db" << _mysql_db |
365 | 0 | << " table=" << _mysql_table << " host=" << _host << " port=" << _port << " user=" << _user |
366 | 0 | << " passwd=" << _passwd << " charset=" << _charset; |
367 | 0 | return out.str(); |
368 | 0 | } |
369 | | |
370 | | JdbcTableDescriptor::JdbcTableDescriptor(const TTableDescriptor& tdesc) |
371 | 0 | : TableDescriptor(tdesc), |
372 | 0 | _jdbc_catalog_id(tdesc.jdbcTable.catalog_id), |
373 | 0 | _jdbc_resource_name(tdesc.jdbcTable.jdbc_resource_name), |
374 | 0 | _jdbc_driver_url(tdesc.jdbcTable.jdbc_driver_url), |
375 | 0 | _jdbc_driver_class(tdesc.jdbcTable.jdbc_driver_class), |
376 | 0 | _jdbc_driver_checksum(tdesc.jdbcTable.jdbc_driver_checksum), |
377 | 0 | _jdbc_url(tdesc.jdbcTable.jdbc_url), |
378 | 0 | _jdbc_table_name(tdesc.jdbcTable.jdbc_table_name), |
379 | 0 | _jdbc_user(tdesc.jdbcTable.jdbc_user), |
380 | 0 | _jdbc_passwd(tdesc.jdbcTable.jdbc_password), |
381 | 0 | _connection_pool_min_size(tdesc.jdbcTable.connection_pool_min_size), |
382 | 0 | _connection_pool_max_size(tdesc.jdbcTable.connection_pool_max_size), |
383 | 0 | _connection_pool_max_wait_time(tdesc.jdbcTable.connection_pool_max_wait_time), |
384 | 0 | _connection_pool_max_life_time(tdesc.jdbcTable.connection_pool_max_life_time), |
385 | 0 | _connection_pool_keep_alive(tdesc.jdbcTable.connection_pool_keep_alive) {} |
386 | | |
387 | 0 | std::string JdbcTableDescriptor::debug_string() const { |
388 | 0 | fmt::memory_buffer buf; |
389 | 0 | fmt::format_to( |
390 | 0 | buf, |
391 | 0 | "JDBCTable({} ,_jdbc_catalog_id = {}, _jdbc_resource_name={} ,_jdbc_driver_url={} " |
392 | 0 | ",_jdbc_driver_class={} ,_jdbc_driver_checksum={} ,_jdbc_url={} " |
393 | 0 | ",_jdbc_table_name={} ,_jdbc_user={} ,_jdbc_passwd={} ,_connection_pool_min_size={} " |
394 | 0 | ",_connection_pool_max_size={} ,_connection_pool_max_wait_time={} " |
395 | 0 | ",_connection_pool_max_life_time={} ,_connection_pool_keep_alive={})", |
396 | 0 | TableDescriptor::debug_string(), _jdbc_catalog_id, _jdbc_resource_name, |
397 | 0 | _jdbc_driver_url, _jdbc_driver_class, _jdbc_driver_checksum, _jdbc_url, |
398 | 0 | _jdbc_table_name, _jdbc_user, _jdbc_passwd, _connection_pool_min_size, |
399 | 0 | _connection_pool_max_size, _connection_pool_max_wait_time, |
400 | 0 | _connection_pool_max_life_time, _connection_pool_keep_alive); |
401 | 0 | return fmt::to_string(buf); |
402 | 0 | } |
403 | | |
404 | | RemoteDorisTableDescriptor::RemoteDorisTableDescriptor(const TTableDescriptor& tdesc) |
405 | 0 | : TableDescriptor(tdesc) {} |
406 | | |
407 | 0 | RemoteDorisTableDescriptor::~RemoteDorisTableDescriptor() = default; |
408 | | |
409 | 0 | std::string RemoteDorisTableDescriptor::debug_string() const { |
410 | 0 | std::stringstream out; |
411 | 0 | out << "RemoteDorisTable(" << TableDescriptor::debug_string() << ")"; |
412 | 0 | return out.str(); |
413 | 0 | } |
414 | | |
415 | | TupleDescriptor::TupleDescriptor(const TTupleDescriptor& tdesc, bool own_slots) |
416 | 1.67M | : _id(tdesc.id), |
417 | 1.67M | _num_materialized_slots(0), |
418 | 1.67M | _has_varlen_slots(false), |
419 | 1.67M | _own_slots(own_slots) {} |
420 | | |
421 | | TupleDescriptor::TupleDescriptor(const PTupleDescriptor& pdesc, bool own_slots) |
422 | 29.6k | : _id(pdesc.id()), |
423 | 29.6k | _num_materialized_slots(0), |
424 | 29.6k | _has_varlen_slots(false), |
425 | 29.6k | _own_slots(own_slots) {} |
426 | | |
427 | 8.53M | void TupleDescriptor::add_slot(SlotDescriptor* slot) { |
428 | 8.53M | _slots.push_back(slot); |
429 | 8.53M | ++_num_materialized_slots; |
430 | | |
431 | 8.53M | if (is_complex_type(slot->type()->get_primitive_type()) || |
432 | 8.53M | is_var_len_object(slot->type()->get_primitive_type()) || |
433 | 8.53M | is_string_type(slot->type()->get_primitive_type())) { |
434 | 3.75M | _has_varlen_slots = true; |
435 | 3.75M | } |
436 | 8.53M | } |
437 | | |
438 | 53.8k | void TupleDescriptor::to_protobuf(PTupleDescriptor* ptuple) const { |
439 | 53.8k | ptuple->Clear(); |
440 | 53.8k | ptuple->set_id(_id); |
441 | | // Useless not set |
442 | 53.8k | ptuple->set_byte_size(0); |
443 | 53.8k | ptuple->set_table_id(-1); |
444 | 53.8k | ptuple->set_num_null_bytes(0); |
445 | 53.8k | } |
446 | | |
447 | 2 | std::string TupleDescriptor::debug_string() const { |
448 | 2 | std::stringstream out; |
449 | 2 | out << "Tuple(id=" << _id; |
450 | 2 | if (_table_desc != nullptr) { |
451 | | //out << " " << _table_desc->debug_string(); |
452 | 0 | } |
453 | | |
454 | 2 | out << " slots=["; |
455 | 8 | for (size_t i = 0; i < _slots.size(); ++i) { |
456 | 6 | if (i > 0) { |
457 | 4 | out << ", "; |
458 | 4 | } |
459 | 6 | out << _slots[i]->debug_string(); |
460 | 6 | } |
461 | | |
462 | 2 | out << "]"; |
463 | 2 | out << " has_varlen_slots=" << _has_varlen_slots; |
464 | 2 | out << ")"; |
465 | 2 | return out.str(); |
466 | 2 | } |
467 | | |
468 | | RowDescriptor::RowDescriptor(const DescriptorTbl& desc_tbl, |
469 | 1.19M | const std::vector<TTupleId>& row_tuples) { |
470 | 1.19M | DCHECK_GT(row_tuples.size(), 0); |
471 | 1.19M | _num_materialized_slots = 0; |
472 | 1.19M | _num_slots = 0; |
473 | | |
474 | 1.28M | for (int row_tuple : row_tuples) { |
475 | 1.28M | TupleDescriptor* tupleDesc = desc_tbl.get_tuple_descriptor(row_tuple); |
476 | 1.28M | _num_materialized_slots += tupleDesc->num_materialized_slots(); |
477 | 1.28M | _num_slots += tupleDesc->slots().size(); |
478 | 1.28M | _tuple_desc_map.push_back(tupleDesc); |
479 | 1.28M | DCHECK(_tuple_desc_map.back() != nullptr); |
480 | 1.28M | } |
481 | | |
482 | 1.19M | init_tuple_idx_map(); |
483 | 1.19M | init_has_varlen_slots(); |
484 | 1.19M | } |
485 | | |
486 | 114k | RowDescriptor::RowDescriptor(TupleDescriptor* tuple_desc) : _tuple_desc_map(1, tuple_desc) { |
487 | 114k | init_tuple_idx_map(); |
488 | 114k | init_has_varlen_slots(); |
489 | 114k | _num_slots = static_cast<int32_t>(tuple_desc->slots().size()); |
490 | 114k | } |
491 | | |
492 | 0 | RowDescriptor::RowDescriptor(const RowDescriptor& lhs_row_desc, const RowDescriptor& rhs_row_desc) { |
493 | 0 | _tuple_desc_map.insert(_tuple_desc_map.end(), lhs_row_desc._tuple_desc_map.begin(), |
494 | 0 | lhs_row_desc._tuple_desc_map.end()); |
495 | 0 | _tuple_desc_map.insert(_tuple_desc_map.end(), rhs_row_desc._tuple_desc_map.begin(), |
496 | 0 | rhs_row_desc._tuple_desc_map.end()); |
497 | 0 | init_tuple_idx_map(); |
498 | 0 | init_has_varlen_slots(); |
499 | |
|
500 | 0 | _num_slots = lhs_row_desc.num_slots() + rhs_row_desc.num_slots(); |
501 | 0 | } |
502 | | |
503 | 1.31M | void RowDescriptor::init_tuple_idx_map() { |
504 | | // find max id |
505 | 1.31M | TupleId max_id = 0; |
506 | 1.39M | for (auto& i : _tuple_desc_map) { |
507 | 1.39M | max_id = std::max(i->id(), max_id); |
508 | 1.39M | } |
509 | | |
510 | 1.31M | _tuple_idx_map.resize(max_id + 1, INVALID_IDX); |
511 | 2.71M | for (int i = 0; i < _tuple_desc_map.size(); ++i) { |
512 | 1.39M | _tuple_idx_map[_tuple_desc_map[i]->id()] = i; |
513 | 1.39M | } |
514 | 1.31M | } |
515 | | |
516 | 1.31M | void RowDescriptor::init_has_varlen_slots() { |
517 | 1.31M | _has_varlen_slots = false; |
518 | 1.37M | for (auto& i : _tuple_desc_map) { |
519 | 1.37M | if (i->has_varlen_slots()) { |
520 | 541k | _has_varlen_slots = true; |
521 | 541k | break; |
522 | 541k | } |
523 | 1.37M | } |
524 | 1.31M | } |
525 | | |
526 | 2.16k | int RowDescriptor::get_tuple_idx(TupleId id) const { |
527 | | // comment CHECK temporarily to make fuzzy test run smoothly |
528 | | // DCHECK_LT(id, _tuple_idx_map.size()) << "RowDescriptor: " << debug_string(); |
529 | 2.16k | if (_tuple_idx_map.size() <= id) { |
530 | 0 | return RowDescriptor::INVALID_IDX; |
531 | 0 | } |
532 | 2.16k | return _tuple_idx_map[id]; |
533 | 2.16k | } |
534 | | |
535 | 0 | void RowDescriptor::to_thrift(std::vector<TTupleId>* row_tuple_ids) { |
536 | 0 | row_tuple_ids->clear(); |
537 | |
|
538 | 0 | for (auto& i : _tuple_desc_map) { |
539 | 0 | row_tuple_ids->push_back(i->id()); |
540 | 0 | } |
541 | 0 | } |
542 | | |
543 | | void RowDescriptor::to_protobuf( |
544 | 0 | google::protobuf::RepeatedField<google::protobuf::int32>* row_tuple_ids) const { |
545 | 0 | row_tuple_ids->Clear(); |
546 | 0 | for (auto* desc : _tuple_desc_map) { |
547 | 0 | row_tuple_ids->Add(desc->id()); |
548 | 0 | } |
549 | 0 | } |
550 | | |
551 | 1.60k | bool RowDescriptor::is_prefix_of(const RowDescriptor& other_desc) const { |
552 | 1.60k | if (_tuple_desc_map.size() > other_desc._tuple_desc_map.size()) { |
553 | 0 | return false; |
554 | 0 | } |
555 | | |
556 | 3.26k | for (int i = 0; i < _tuple_desc_map.size(); ++i) { |
557 | | // pointer comparison okay, descriptors are unique |
558 | 1.66k | if (_tuple_desc_map[i] != other_desc._tuple_desc_map[i]) { |
559 | 0 | return false; |
560 | 0 | } |
561 | 1.66k | } |
562 | | |
563 | 1.60k | return true; |
564 | 1.60k | } |
565 | | |
566 | 0 | bool RowDescriptor::equals(const RowDescriptor& other_desc) const { |
567 | 0 | if (_tuple_desc_map.size() != other_desc._tuple_desc_map.size()) { |
568 | 0 | return false; |
569 | 0 | } |
570 | | |
571 | 0 | for (int i = 0; i < _tuple_desc_map.size(); ++i) { |
572 | | // pointer comparison okay, descriptors are unique |
573 | 0 | if (_tuple_desc_map[i] != other_desc._tuple_desc_map[i]) { |
574 | 0 | return false; |
575 | 0 | } |
576 | 0 | } |
577 | | |
578 | 0 | return true; |
579 | 0 | } |
580 | | |
581 | 0 | std::string RowDescriptor::debug_string() const { |
582 | 0 | std::stringstream ss; |
583 | |
|
584 | 0 | ss << "tuple_desc_map: ["; |
585 | 0 | for (int i = 0; i < _tuple_desc_map.size(); ++i) { |
586 | 0 | ss << _tuple_desc_map[i]->debug_string(); |
587 | 0 | if (i != _tuple_desc_map.size() - 1) { |
588 | 0 | ss << ", "; |
589 | 0 | } |
590 | 0 | } |
591 | 0 | ss << "] "; |
592 | |
|
593 | 0 | ss << "tuple_id_map: ["; |
594 | 0 | for (int i = 0; i < _tuple_idx_map.size(); ++i) { |
595 | 0 | ss << _tuple_idx_map[i]; |
596 | 0 | if (i != _tuple_idx_map.size() - 1) { |
597 | 0 | ss << ", "; |
598 | 0 | } |
599 | 0 | } |
600 | 0 | ss << "] "; |
601 | |
|
602 | 0 | return ss.str(); |
603 | 0 | } |
604 | | |
605 | 4.22M | int RowDescriptor::get_column_id(int slot_id) const { |
606 | 4.22M | int column_id_counter = 0; |
607 | 4.23M | for (auto* const tuple_desc : _tuple_desc_map) { |
608 | 24.1M | for (auto* const slot : tuple_desc->slots()) { |
609 | 24.1M | if (slot->id() == slot_id) { |
610 | 4.22M | return column_id_counter; |
611 | 4.22M | } |
612 | 19.9M | column_id_counter++; |
613 | 19.9M | } |
614 | 4.23M | } |
615 | 1.45k | return -1; |
616 | 4.22M | } |
617 | | |
618 | | Status DescriptorTbl::create(ObjectPool* pool, const TDescriptorTable& thrift_tbl, |
619 | 510k | DescriptorTbl** tbl) { |
620 | 510k | *tbl = pool->add(new DescriptorTbl()); |
621 | | |
622 | | // deserialize table descriptors first, they are being referenced by tuple descriptors |
623 | 510k | for (const auto& tdesc : thrift_tbl.tableDescriptors) { |
624 | 377k | TableDescriptor* desc = nullptr; |
625 | | |
626 | 377k | switch (tdesc.tableType) { |
627 | 85 | case TTableType::MYSQL_TABLE: |
628 | 85 | desc = pool->add(new MySQLTableDescriptor(tdesc)); |
629 | 85 | break; |
630 | | |
631 | 373k | case TTableType::OLAP_TABLE: |
632 | 373k | desc = pool->add(new OlapTableDescriptor(tdesc)); |
633 | 373k | break; |
634 | | |
635 | 3.04k | case TTableType::SCHEMA_TABLE: |
636 | 3.04k | desc = pool->add(new SchemaTableDescriptor(tdesc)); |
637 | 3.04k | break; |
638 | 0 | case TTableType::BROKER_TABLE: |
639 | 0 | desc = pool->add(new BrokerTableDescriptor(tdesc)); |
640 | 0 | break; |
641 | 0 | case TTableType::ES_TABLE: |
642 | 0 | desc = pool->add(new EsTableDescriptor(tdesc)); |
643 | 0 | break; |
644 | 36 | case TTableType::HIVE_TABLE: |
645 | 36 | desc = pool->add(new HiveTableDescriptor(tdesc)); |
646 | 36 | break; |
647 | 0 | case TTableType::ICEBERG_TABLE: |
648 | 0 | desc = pool->add(new IcebergTableDescriptor(tdesc)); |
649 | 0 | break; |
650 | 0 | case TTableType::JDBC_TABLE: |
651 | 0 | desc = pool->add(new JdbcTableDescriptor(tdesc)); |
652 | 0 | break; |
653 | 0 | case TTableType::MAX_COMPUTE_TABLE: |
654 | 0 | desc = pool->add(new MaxComputeTableDescriptor(tdesc)); |
655 | 0 | break; |
656 | 0 | case TTableType::TRINO_CONNECTOR_TABLE: |
657 | 0 | desc = pool->add(new TrinoConnectorTableDescriptor(tdesc)); |
658 | 0 | break; |
659 | 0 | case TTableType::DICTIONARY_TABLE: |
660 | 0 | desc = pool->add(new DictionaryTableDescriptor(tdesc)); |
661 | 0 | break; |
662 | 0 | case TTableType::REMOTE_DORIS_TABLE: |
663 | 0 | desc = pool->add(new RemoteDorisTableDescriptor(tdesc)); |
664 | 0 | break; |
665 | 0 | default: |
666 | 0 | DCHECK(false) << "invalid table type: " << tdesc.tableType; |
667 | 377k | } |
668 | | |
669 | 376k | (*tbl)->_tbl_desc_map[static_cast<int32_t>(tdesc.id)] = desc; |
670 | 376k | } |
671 | | |
672 | 1.59M | for (const auto& tdesc : thrift_tbl.tupleDescriptors) { |
673 | 1.59M | TupleDescriptor* desc = pool->add(new TupleDescriptor(tdesc)); |
674 | | |
675 | | // fix up table pointer |
676 | 1.59M | if (tdesc.__isset.tableId) { |
677 | 699k | desc->_table_desc = (*tbl)->get_table_descriptor(static_cast<int32_t>(tdesc.tableId)); |
678 | 699k | DCHECK(desc->_table_desc != nullptr); |
679 | 699k | } |
680 | | |
681 | 1.59M | (*tbl)->_tuple_desc_map[tdesc.id] = desc; |
682 | 1.59M | (*tbl)->_row_tuples.emplace_back(tdesc.id); |
683 | 1.59M | } |
684 | | |
685 | 7.71M | for (const auto& tdesc : thrift_tbl.slotDescriptors) { |
686 | 7.71M | SlotDescriptor* slot_d = pool->add(new SlotDescriptor(tdesc)); |
687 | 7.71M | (*tbl)->_slot_desc_map[tdesc.id] = slot_d; |
688 | | |
689 | | // link to parent |
690 | 7.71M | auto entry = (*tbl)->_tuple_desc_map.find(tdesc.parent); |
691 | | |
692 | 7.71M | if (entry == (*tbl)->_tuple_desc_map.end()) { |
693 | 0 | return Status::InternalError("unknown tid in slot descriptor msg"); |
694 | 0 | } |
695 | 7.71M | entry->second->add_slot(slot_d); |
696 | 7.71M | } |
697 | | |
698 | 510k | return Status::OK(); |
699 | 510k | } |
700 | | |
701 | 698k | TableDescriptor* DescriptorTbl::get_table_descriptor(TableId id) const { |
702 | | // TODO: is there some boost function to do exactly this? |
703 | 698k | auto i = _tbl_desc_map.find(id); |
704 | | |
705 | 698k | if (i == _tbl_desc_map.end()) { |
706 | 0 | return nullptr; |
707 | 698k | } else { |
708 | 698k | return i->second; |
709 | 698k | } |
710 | 698k | } |
711 | | |
712 | 2.12M | TupleDescriptor* DescriptorTbl::get_tuple_descriptor(TupleId id) const { |
713 | | // TODO: is there some boost function to do exactly this? |
714 | 2.12M | auto i = _tuple_desc_map.find(id); |
715 | | |
716 | 2.12M | if (i == _tuple_desc_map.end()) { |
717 | 171k | return nullptr; |
718 | 1.95M | } else { |
719 | 1.95M | return i->second; |
720 | 1.95M | } |
721 | 2.12M | } |
722 | | |
723 | 3.89M | SlotDescriptor* DescriptorTbl::get_slot_descriptor(SlotId id) const { |
724 | | // TODO: is there some boost function to do exactly this? |
725 | 3.89M | auto i = _slot_desc_map.find(id); |
726 | | |
727 | 3.89M | if (i == _slot_desc_map.end()) { |
728 | 0 | return nullptr; |
729 | 3.89M | } else { |
730 | 3.89M | return i->second; |
731 | 3.89M | } |
732 | 3.89M | } |
733 | | |
734 | 0 | std::string DescriptorTbl::debug_string() const { |
735 | 0 | std::stringstream out; |
736 | 0 | out << "tuples:\n"; |
737 | |
|
738 | 0 | for (auto i : _tuple_desc_map) { |
739 | 0 | out << i.second->debug_string() << '\n'; |
740 | 0 | } |
741 | |
|
742 | 0 | return out.str(); |
743 | 0 | } |
744 | | } // namespace doris |