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 | | |
50 | | SlotDescriptor::SlotDescriptor(const TSlotDescriptor& tdesc) |
51 | 9.34M | : _id(tdesc.id), |
52 | 9.34M | _type(DataTypeFactory::instance().create_data_type(tdesc.slotType, |
53 | 9.34M | tdesc.nullIndicatorBit != -1)), |
54 | 9.34M | _parent(tdesc.parent), |
55 | 9.34M | _col_pos(tdesc.columnPos), |
56 | 9.34M | _col_name(tdesc.colName), |
57 | 9.34M | _col_name_lower_case(to_lower(tdesc.colName)), |
58 | 9.34M | _col_unique_id(tdesc.col_unique_id), |
59 | 9.34M | _slot_idx(tdesc.slotIdx), |
60 | 9.34M | _field_idx(-1), |
61 | 9.34M | _is_key(tdesc.is_key), |
62 | 9.34M | _column_paths(tdesc.column_paths), |
63 | 9.34M | _all_access_paths(tdesc.__isset.all_access_paths ? tdesc.all_access_paths |
64 | 9.34M | : TColumnAccessPaths {}), |
65 | 9.34M | _predicate_access_paths(tdesc.__isset.predicate_access_paths |
66 | 9.34M | ? tdesc.predicate_access_paths |
67 | 9.34M | : TColumnAccessPaths {}), |
68 | 18.4E | _is_auto_increment(tdesc.__isset.is_auto_increment ? tdesc.is_auto_increment : false), |
69 | 9.34M | _col_default_value(tdesc.__isset.col_default_value ? tdesc.col_default_value : "") { |
70 | 9.34M | if (tdesc.__isset.virtual_column_expr) { |
71 | | // Make sure virtual column is valid. |
72 | 416 | if (tdesc.virtual_column_expr.nodes.empty()) { |
73 | 2 | throw doris::Exception(doris::ErrorCode::FATAL_ERROR, |
74 | 2 | "Virtual column expr node is empty, col_name: {}, " |
75 | 2 | "col_unique_id: {}", |
76 | 2 | tdesc.colName, tdesc.col_unique_id); |
77 | 2 | } |
78 | 414 | const auto& node = tdesc.virtual_column_expr.nodes[0]; |
79 | 414 | if (node.node_type == TExprNodeType::SLOT_REF) { |
80 | 2 | throw doris::Exception(doris::ErrorCode::FATAL_ERROR, |
81 | 2 | "Virtual column expr node is slot ref, col_name: {}, " |
82 | 2 | "col_unique_id: {}", |
83 | 2 | tdesc.colName, tdesc.col_unique_id); |
84 | 2 | } |
85 | 412 | this->virtual_column_expr = std::make_shared<doris::TExpr>(tdesc.virtual_column_expr); |
86 | 412 | } |
87 | 9.34M | } |
88 | | |
89 | | SlotDescriptor::SlotDescriptor(const PSlotDescriptor& pdesc) |
90 | 286k | : _id(pdesc.id()), |
91 | 286k | _type(DataTypeFactory::instance().create_data_type(pdesc.slot_type(), |
92 | 286k | pdesc.null_indicator_bit() != -1)), |
93 | 286k | _parent(pdesc.parent()), |
94 | 286k | _col_pos(pdesc.column_pos()), |
95 | 286k | _col_name(pdesc.col_name()), |
96 | 286k | _col_name_lower_case(to_lower(pdesc.col_name())), |
97 | 286k | _col_unique_id(pdesc.col_unique_id()), |
98 | 286k | _slot_idx(pdesc.slot_idx()), |
99 | 286k | _field_idx(-1), |
100 | 286k | _is_key(pdesc.is_key()), |
101 | 286k | _column_paths(pdesc.column_paths().begin(), pdesc.column_paths().end()), |
102 | 286k | _is_auto_increment(pdesc.is_auto_increment()) { |
103 | 286k | auto convert_to_thrift_column_access_path = [](const PColumnAccessPath& pb_path) { |
104 | 808 | TColumnAccessPath thrift_path; |
105 | 808 | thrift_path.type = (TAccessPathType::type)pb_path.type(); |
106 | 808 | if (pb_path.has_version()) { |
107 | 808 | thrift_path.__set_version(pb_path.version()); |
108 | 808 | } |
109 | 808 | if (pb_path.has_data_access_path()) { |
110 | 808 | thrift_path.__isset.data_access_path = true; |
111 | 1.96k | for (int i = 0; i < pb_path.data_access_path().path_size(); ++i) { |
112 | 1.15k | thrift_path.data_access_path.path.push_back(pb_path.data_access_path().path(i)); |
113 | 1.15k | } |
114 | 808 | } |
115 | 808 | if (pb_path.has_meta_access_path()) { |
116 | 0 | thrift_path.__isset.meta_access_path = true; |
117 | 0 | for (int i = 0; i < pb_path.meta_access_path().path_size(); ++i) { |
118 | 0 | thrift_path.meta_access_path.path.push_back(pb_path.meta_access_path().path(i)); |
119 | 0 | } |
120 | 0 | } |
121 | 808 | return thrift_path; |
122 | 808 | }; |
123 | 286k | for (const auto& pb_path : pdesc.all_access_paths()) { |
124 | 812 | _all_access_paths.push_back(convert_to_thrift_column_access_path(pb_path)); |
125 | 812 | } |
126 | 286k | for (const auto& pb_path : pdesc.predicate_access_paths()) { |
127 | 1 | _predicate_access_paths.push_back(convert_to_thrift_column_access_path(pb_path)); |
128 | 1 | } |
129 | 286k | } |
130 | | |
131 | | #ifdef BE_TEST |
132 | | SlotDescriptor::SlotDescriptor() |
133 | | : _id(0), |
134 | | _type(nullptr), |
135 | | _parent(0), |
136 | | _col_pos(0), |
137 | | _col_unique_id(0), |
138 | | _slot_idx(0), |
139 | | _field_idx(-1), |
140 | | _is_key(false), |
141 | | _is_auto_increment(false) {} |
142 | | #endif |
143 | | |
144 | 354k | void SlotDescriptor::to_protobuf(PSlotDescriptor* pslot) const { |
145 | 354k | pslot->set_id(_id); |
146 | 354k | pslot->set_parent(_parent); |
147 | 354k | _type->to_protobuf(pslot->mutable_slot_type()); |
148 | 354k | pslot->set_column_pos(_col_pos); |
149 | 354k | pslot->set_byte_offset(0); |
150 | 354k | pslot->set_null_indicator_byte(0); |
151 | 354k | pslot->set_null_indicator_bit(_type->is_nullable() ? 0 : -1); |
152 | 354k | pslot->set_col_name(_col_name); |
153 | 354k | pslot->set_slot_idx(_slot_idx); |
154 | 354k | pslot->set_col_unique_id(_col_unique_id); |
155 | 354k | pslot->set_is_key(_is_key); |
156 | 354k | pslot->set_is_auto_increment(_is_auto_increment); |
157 | 354k | pslot->set_col_type(_type->get_primitive_type()); |
158 | 354k | for (const std::string& path : _column_paths) { |
159 | 93 | pslot->add_column_paths(path); |
160 | 93 | } |
161 | 354k | auto convert_to_protobuf_column_access_path = [](const TColumnAccessPath& thrift_path, |
162 | 354k | doris::PColumnAccessPath* pb_path) { |
163 | 805 | pb_path->Clear(); |
164 | 805 | pb_path->set_type((PAccessPathType)thrift_path.type); // 使用 reinterpret_cast 进行类型转换 |
165 | 805 | if (thrift_path.__isset.version) { |
166 | 805 | pb_path->set_version(thrift_path.version); |
167 | 805 | } |
168 | 805 | if (thrift_path.__isset.data_access_path) { |
169 | 805 | auto* pb_data = pb_path->mutable_data_access_path(); |
170 | 805 | pb_data->Clear(); |
171 | 1.13k | for (const auto& s : thrift_path.data_access_path.path) { |
172 | 1.13k | pb_data->add_path(s); |
173 | 1.13k | } |
174 | 805 | } |
175 | 805 | if (thrift_path.__isset.meta_access_path) { |
176 | 0 | auto* pb_meta = pb_path->mutable_meta_access_path(); |
177 | 0 | pb_meta->Clear(); |
178 | 0 | for (const auto& s : thrift_path.meta_access_path.path) { |
179 | 0 | pb_meta->add_path(s); |
180 | 0 | } |
181 | 0 | } |
182 | 805 | }; |
183 | 354k | for (const auto& path : _all_access_paths) { |
184 | 809 | auto* pb_path = pslot->add_all_access_paths(); |
185 | 809 | convert_to_protobuf_column_access_path(path, pb_path); |
186 | 809 | } |
187 | 354k | for (const auto& path : _predicate_access_paths) { |
188 | 1 | auto* pb_path = pslot->add_predicate_access_paths(); |
189 | 1 | convert_to_protobuf_column_access_path(path, pb_path); |
190 | 1 | } |
191 | 354k | } |
192 | | |
193 | 27.4M | DataTypePtr SlotDescriptor::get_data_type_ptr() const { |
194 | 27.4M | return get_data_type_with_default_argument(type()); |
195 | 27.4M | } |
196 | | |
197 | 13.2M | MutableColumnPtr SlotDescriptor::get_empty_mutable_column() const { |
198 | 13.2M | if (this->get_virtual_column_expr() != nullptr) { |
199 | 757 | return ColumnNothing::create(0); |
200 | 757 | } |
201 | | |
202 | 13.2M | return type()->create_column(); |
203 | 13.2M | } |
204 | | |
205 | 45.8M | bool SlotDescriptor::is_nullable() const { |
206 | 45.8M | return _type->is_nullable(); |
207 | 45.8M | } |
208 | | |
209 | 1.06M | PrimitiveType SlotDescriptor::col_type() const { |
210 | 1.06M | return _type->get_primitive_type(); |
211 | 1.06M | } |
212 | | |
213 | 8 | std::string SlotDescriptor::debug_string() const { |
214 | 8 | const bool is_virtual = this->get_virtual_column_expr() != nullptr; |
215 | 8 | return fmt::format( |
216 | 8 | "SlotDescriptor(id={}, type={}, col_name={}, col_unique_id={}, " |
217 | 8 | "is_virtual={})", |
218 | 8 | _id, _type->get_name(), _col_name, _col_unique_id, is_virtual); |
219 | 8 | } |
220 | | |
221 | | TableDescriptor::TableDescriptor(const TTableDescriptor& tdesc) |
222 | 416k | : _table_type(tdesc.tableType), |
223 | 416k | _name(tdesc.tableName), |
224 | 416k | _database(tdesc.dbName), |
225 | 416k | _table_id(tdesc.id), |
226 | 416k | _num_cols(tdesc.numCols), |
227 | 416k | _num_clustering_cols(tdesc.numClusteringCols) {} |
228 | | |
229 | 0 | std::string TableDescriptor::debug_string() const { |
230 | 0 | std::stringstream out; |
231 | 0 | out << "#cols=" << _num_cols << " #clustering_cols=" << _num_clustering_cols; |
232 | 0 | return out.str(); |
233 | 0 | } |
234 | | |
235 | 412k | OlapTableDescriptor::OlapTableDescriptor(const TTableDescriptor& tdesc) : TableDescriptor(tdesc) {} |
236 | | |
237 | 0 | std::string OlapTableDescriptor::debug_string() const { |
238 | 0 | std::stringstream out; |
239 | 0 | out << "OlapTable(" << TableDescriptor::debug_string() << ")"; |
240 | 0 | return out.str(); |
241 | 0 | } |
242 | | |
243 | | DictionaryTableDescriptor::DictionaryTableDescriptor(const TTableDescriptor& tdesc) |
244 | 0 | : TableDescriptor(tdesc) {} |
245 | | |
246 | 0 | std::string DictionaryTableDescriptor::debug_string() const { |
247 | 0 | std::stringstream out; |
248 | 0 | out << "Dictionary(" << TableDescriptor::debug_string() << ")"; |
249 | 0 | return out.str(); |
250 | 0 | } |
251 | | |
252 | | SchemaTableDescriptor::SchemaTableDescriptor(const TTableDescriptor& tdesc) |
253 | 3.39k | : TableDescriptor(tdesc), _schema_table_type(tdesc.schemaTable.tableType) {} |
254 | 3.39k | SchemaTableDescriptor::~SchemaTableDescriptor() = default; |
255 | | |
256 | 0 | std::string SchemaTableDescriptor::debug_string() const { |
257 | 0 | std::stringstream out; |
258 | 0 | out << "SchemaTable(" << TableDescriptor::debug_string() << ")"; |
259 | 0 | return out.str(); |
260 | 0 | } |
261 | | |
262 | | BrokerTableDescriptor::BrokerTableDescriptor(const TTableDescriptor& tdesc) |
263 | 0 | : TableDescriptor(tdesc) {} |
264 | | |
265 | 0 | BrokerTableDescriptor::~BrokerTableDescriptor() = default; |
266 | | |
267 | 0 | std::string BrokerTableDescriptor::debug_string() const { |
268 | 0 | std::stringstream out; |
269 | 0 | out << "BrokerTable(" << TableDescriptor::debug_string() << ")"; |
270 | 0 | return out.str(); |
271 | 0 | } |
272 | | |
273 | 36 | HiveTableDescriptor::HiveTableDescriptor(const TTableDescriptor& tdesc) : TableDescriptor(tdesc) {} |
274 | | |
275 | 36 | HiveTableDescriptor::~HiveTableDescriptor() = default; |
276 | | |
277 | 0 | std::string HiveTableDescriptor::debug_string() const { |
278 | 0 | std::stringstream out; |
279 | 0 | out << "HiveTable(" << TableDescriptor::debug_string() << ")"; |
280 | 0 | return out.str(); |
281 | 0 | } |
282 | | |
283 | | IcebergTableDescriptor::IcebergTableDescriptor(const TTableDescriptor& tdesc) |
284 | 0 | : TableDescriptor(tdesc) {} |
285 | | |
286 | 0 | IcebergTableDescriptor::~IcebergTableDescriptor() = default; |
287 | | |
288 | 0 | std::string IcebergTableDescriptor::debug_string() const { |
289 | 0 | std::stringstream out; |
290 | 0 | out << "IcebergTable(" << TableDescriptor::debug_string() << ")"; |
291 | 0 | return out.str(); |
292 | 0 | } |
293 | | |
294 | | MaxComputeTableDescriptor::MaxComputeTableDescriptor(const TTableDescriptor& tdesc) |
295 | 0 | : TableDescriptor(tdesc), |
296 | 0 | _region(tdesc.mcTable.region), |
297 | 0 | _project(tdesc.mcTable.project), |
298 | 0 | _table(tdesc.mcTable.table), |
299 | 0 | _odps_url(tdesc.mcTable.odps_url), |
300 | 0 | _tunnel_url(tdesc.mcTable.tunnel_url), |
301 | 0 | _access_key(tdesc.mcTable.access_key), |
302 | 0 | _secret_key(tdesc.mcTable.secret_key), |
303 | 0 | _public_access(tdesc.mcTable.public_access) { |
304 | 0 | if (tdesc.mcTable.__isset.endpoint) { |
305 | 0 | _endpoint = tdesc.mcTable.endpoint; |
306 | 0 | } else { |
307 | 0 | _init_status = Status::InvalidArgument( |
308 | 0 | "fail to init MaxComputeTableDescriptor, missing endpoint."); |
309 | 0 | } |
310 | |
|
311 | 0 | if (tdesc.mcTable.__isset.quota) { |
312 | 0 | _quota = tdesc.mcTable.quota; |
313 | 0 | } else { |
314 | 0 | _init_status = |
315 | 0 | Status::InvalidArgument("fail to init MaxComputeTableDescriptor, missing quota."); |
316 | 0 | } |
317 | |
|
318 | 0 | if (tdesc.mcTable.__isset.properties) [[likely]] { |
319 | 0 | _props = tdesc.mcTable.properties; |
320 | 0 | } else { |
321 | 0 | static const std::string MC_ACCESS_KEY = "mc.access_key"; |
322 | 0 | static const std::string MC_SECRET_KEY = "mc.secret_key"; |
323 | 0 | _props.insert({MC_ACCESS_KEY, _access_key}); |
324 | 0 | _props.insert({MC_SECRET_KEY, _secret_key}); |
325 | 0 | } |
326 | 0 | } |
327 | | |
328 | 0 | MaxComputeTableDescriptor::~MaxComputeTableDescriptor() = default; |
329 | | |
330 | 0 | std::string MaxComputeTableDescriptor::debug_string() const { |
331 | 0 | std::stringstream out; |
332 | 0 | out << "MaxComputeTable(" << TableDescriptor::debug_string() << ")"; |
333 | 0 | return out.str(); |
334 | 0 | } |
335 | | |
336 | | TrinoConnectorTableDescriptor::TrinoConnectorTableDescriptor(const TTableDescriptor& tdesc) |
337 | 0 | : TableDescriptor(tdesc) {} |
338 | | |
339 | 0 | TrinoConnectorTableDescriptor::~TrinoConnectorTableDescriptor() = default; |
340 | | |
341 | 0 | std::string TrinoConnectorTableDescriptor::debug_string() const { |
342 | 0 | std::stringstream out; |
343 | 0 | out << "TrinoConnectorTable(" << TableDescriptor::debug_string() << ")"; |
344 | 0 | return out.str(); |
345 | 0 | } |
346 | | |
347 | 0 | EsTableDescriptor::EsTableDescriptor(const TTableDescriptor& tdesc) : TableDescriptor(tdesc) {} |
348 | | |
349 | 0 | EsTableDescriptor::~EsTableDescriptor() = default; |
350 | | |
351 | 0 | std::string EsTableDescriptor::debug_string() const { |
352 | 0 | std::stringstream out; |
353 | 0 | out << "EsTable(" << TableDescriptor::debug_string() << ")"; |
354 | 0 | return out.str(); |
355 | 0 | } |
356 | | |
357 | | MySQLTableDescriptor::MySQLTableDescriptor(const TTableDescriptor& tdesc) |
358 | 91 | : TableDescriptor(tdesc), |
359 | 91 | _mysql_db(tdesc.mysqlTable.db), |
360 | 91 | _mysql_table(tdesc.mysqlTable.table), |
361 | 91 | _host(tdesc.mysqlTable.host), |
362 | 91 | _port(tdesc.mysqlTable.port), |
363 | 91 | _user(tdesc.mysqlTable.user), |
364 | 91 | _passwd(tdesc.mysqlTable.passwd), |
365 | 91 | _charset(tdesc.mysqlTable.charset) {} |
366 | | |
367 | 0 | std::string MySQLTableDescriptor::debug_string() const { |
368 | 0 | std::stringstream out; |
369 | 0 | out << "MySQLTable(" << TableDescriptor::debug_string() << " _db" << _mysql_db |
370 | 0 | << " table=" << _mysql_table << " host=" << _host << " port=" << _port << " user=" << _user |
371 | 0 | << " passwd=" << _passwd << " charset=" << _charset; |
372 | 0 | return out.str(); |
373 | 0 | } |
374 | | |
375 | | JdbcTableDescriptor::JdbcTableDescriptor(const TTableDescriptor& tdesc) |
376 | 4 | : TableDescriptor(tdesc), |
377 | 4 | _jdbc_catalog_id(tdesc.jdbcTable.catalog_id), |
378 | 4 | _jdbc_resource_name(tdesc.jdbcTable.jdbc_resource_name), |
379 | 4 | _jdbc_driver_url(tdesc.jdbcTable.jdbc_driver_url), |
380 | 4 | _jdbc_driver_class(tdesc.jdbcTable.jdbc_driver_class), |
381 | 4 | _jdbc_driver_checksum(tdesc.jdbcTable.jdbc_driver_checksum), |
382 | 4 | _jdbc_url(tdesc.jdbcTable.jdbc_url), |
383 | 4 | _jdbc_table_name(tdesc.jdbcTable.jdbc_table_name), |
384 | 4 | _jdbc_user(tdesc.jdbcTable.jdbc_user), |
385 | 4 | _jdbc_passwd(tdesc.jdbcTable.jdbc_password), |
386 | 4 | _connection_pool_min_size(tdesc.jdbcTable.connection_pool_min_size), |
387 | 4 | _connection_pool_max_size(tdesc.jdbcTable.connection_pool_max_size), |
388 | 4 | _connection_pool_max_wait_time(tdesc.jdbcTable.connection_pool_max_wait_time), |
389 | 4 | _connection_pool_max_life_time(tdesc.jdbcTable.connection_pool_max_life_time), |
390 | 4 | _connection_pool_keep_alive(tdesc.jdbcTable.connection_pool_keep_alive) {} |
391 | | |
392 | 0 | std::string JdbcTableDescriptor::debug_string() const { |
393 | 0 | fmt::memory_buffer buf; |
394 | 0 | fmt::format_to( |
395 | 0 | buf, |
396 | 0 | "JDBCTable({} ,_jdbc_catalog_id = {}, _jdbc_resource_name={} ,_jdbc_driver_url={} " |
397 | 0 | ",_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 | TableDescriptor::debug_string(), _jdbc_catalog_id, _jdbc_resource_name, |
402 | 0 | _jdbc_driver_url, _jdbc_driver_class, _jdbc_driver_checksum, _jdbc_url, |
403 | 0 | _jdbc_table_name, _jdbc_user, _jdbc_passwd, _connection_pool_min_size, |
404 | 0 | _connection_pool_max_size, _connection_pool_max_wait_time, |
405 | 0 | _connection_pool_max_life_time, _connection_pool_keep_alive); |
406 | 0 | return fmt::to_string(buf); |
407 | 0 | } |
408 | | |
409 | | RemoteDorisTableDescriptor::RemoteDorisTableDescriptor(const TTableDescriptor& tdesc) |
410 | 0 | : TableDescriptor(tdesc) {} |
411 | | |
412 | 0 | RemoteDorisTableDescriptor::~RemoteDorisTableDescriptor() = default; |
413 | | |
414 | 0 | std::string RemoteDorisTableDescriptor::debug_string() const { |
415 | 0 | std::stringstream out; |
416 | 0 | out << "RemoteDorisTable(" << TableDescriptor::debug_string() << ")"; |
417 | 0 | return out.str(); |
418 | 0 | } |
419 | | |
420 | | TupleDescriptor::TupleDescriptor(const TTupleDescriptor& tdesc, bool own_slots) |
421 | 1.83M | : _id(tdesc.id), |
422 | 1.83M | _num_materialized_slots(0), |
423 | 1.83M | _has_varlen_slots(false), |
424 | 1.83M | _own_slots(own_slots) {} |
425 | | |
426 | | TupleDescriptor::TupleDescriptor(const PTupleDescriptor& pdesc, bool own_slots) |
427 | 32.2k | : _id(pdesc.id()), |
428 | 32.2k | _num_materialized_slots(0), |
429 | 32.2k | _has_varlen_slots(false), |
430 | 32.2k | _own_slots(own_slots) {} |
431 | | |
432 | 9.63M | void TupleDescriptor::add_slot(SlotDescriptor* slot) { |
433 | 9.63M | _slots.push_back(slot); |
434 | 9.63M | ++_num_materialized_slots; |
435 | | |
436 | 9.63M | if (is_complex_type(slot->type()->get_primitive_type()) || |
437 | 9.63M | is_var_len_object(slot->type()->get_primitive_type()) || |
438 | 9.63M | is_string_type(slot->type()->get_primitive_type())) { |
439 | 4.19M | _has_varlen_slots = true; |
440 | 4.19M | } |
441 | 9.63M | } |
442 | | |
443 | 47.4k | void TupleDescriptor::to_protobuf(PTupleDescriptor* ptuple) const { |
444 | 47.4k | ptuple->Clear(); |
445 | 47.4k | ptuple->set_id(_id); |
446 | | // Useless not set |
447 | 47.4k | ptuple->set_byte_size(0); |
448 | 47.4k | ptuple->set_table_id(-1); |
449 | 47.4k | ptuple->set_num_null_bytes(0); |
450 | 47.4k | } |
451 | | |
452 | 2 | std::string TupleDescriptor::debug_string() const { |
453 | 2 | std::stringstream out; |
454 | 2 | out << "Tuple(id=" << _id; |
455 | 2 | if (_table_desc != nullptr) { |
456 | | //out << " " << _table_desc->debug_string(); |
457 | 0 | } |
458 | | |
459 | 2 | out << " slots=["; |
460 | 8 | for (size_t i = 0; i < _slots.size(); ++i) { |
461 | 6 | if (i > 0) { |
462 | 4 | out << ", "; |
463 | 4 | } |
464 | 6 | out << _slots[i]->debug_string(); |
465 | 6 | } |
466 | | |
467 | 2 | out << "]"; |
468 | 2 | out << " has_varlen_slots=" << _has_varlen_slots; |
469 | 2 | out << ")"; |
470 | 2 | return out.str(); |
471 | 2 | } |
472 | | |
473 | 4.59M | int TupleDescriptor::get_column_id(SlotId slot_id) const { |
474 | 26.8M | for (int column_id = 0; auto* slot : slots()) { |
475 | 26.8M | if (slot->id() == slot_id) { |
476 | 4.58M | return column_id; |
477 | 4.58M | } |
478 | 22.2M | ++column_id; |
479 | 22.2M | } |
480 | 7.77k | return -1; |
481 | 4.59M | } |
482 | | |
483 | | RowDescriptor::RowDescriptor(const DescriptorTbl& desc_tbl, |
484 | 1.38M | const std::vector<TTupleId>& row_tuples) { |
485 | 1.38M | DCHECK_GT(row_tuples.size(), 0); |
486 | | |
487 | 1.48M | for (int row_tuple : row_tuples) { |
488 | 1.48M | TupleDescriptor* tupleDesc = desc_tbl.get_tuple_descriptor(row_tuple); |
489 | 1.48M | _tuple_desc_map.push_back(tupleDesc); |
490 | 1.48M | DCHECK(_tuple_desc_map.back() != nullptr); |
491 | 1.48M | } |
492 | 1.38M | } |
493 | | |
494 | 102k | RowDescriptor::RowDescriptor(TupleDescriptor* tuple_desc) : _tuple_desc_map(1, tuple_desc) {} |
495 | | |
496 | 12.1M | int RowDescriptor::num_slots() const { |
497 | 12.1M | int count = 0; |
498 | 12.1M | for (const auto* tuple_desc : _tuple_desc_map) { |
499 | 11.0M | count += tuple_desc->slots().size(); |
500 | 11.0M | } |
501 | 12.1M | return count; |
502 | 12.1M | } |
503 | | |
504 | 0 | std::string RowDescriptor::debug_string() const { |
505 | 0 | std::stringstream ss; |
506 | |
|
507 | 0 | ss << "tuple_desc_map: ["; |
508 | 0 | for (int i = 0; i < _tuple_desc_map.size(); ++i) { |
509 | 0 | ss << _tuple_desc_map[i]->debug_string(); |
510 | 0 | if (i != _tuple_desc_map.size() - 1) { |
511 | 0 | ss << ", "; |
512 | 0 | } |
513 | 0 | } |
514 | 0 | ss << "] "; |
515 | |
|
516 | 0 | return ss.str(); |
517 | 0 | } |
518 | | |
519 | 4.58M | int RowDescriptor::get_column_id(int slot_id) const { |
520 | 4.58M | int column_id_counter = 0; |
521 | 4.59M | for (auto* const tuple_desc : _tuple_desc_map) { |
522 | 4.59M | int tuple_column_id = tuple_desc->get_column_id(slot_id); |
523 | 4.59M | if (tuple_column_id != -1) { |
524 | 4.58M | return column_id_counter + tuple_column_id; |
525 | 4.58M | } |
526 | 10.6k | column_id_counter += tuple_desc->slots().size(); |
527 | 10.6k | } |
528 | 4.47k | return -1; |
529 | 4.58M | } |
530 | | |
531 | | Status DescriptorTbl::create(ObjectPool* pool, const TDescriptorTable& thrift_tbl, |
532 | 564k | DescriptorTbl** tbl) { |
533 | 564k | *tbl = pool->add(new DescriptorTbl()); |
534 | | |
535 | | // deserialize table descriptors first, they are being referenced by tuple descriptors |
536 | 564k | for (const auto& tdesc : thrift_tbl.tableDescriptors) { |
537 | 419k | TableDescriptor* desc = nullptr; |
538 | | |
539 | 419k | switch (tdesc.tableType) { |
540 | 91 | case TTableType::MYSQL_TABLE: |
541 | 91 | desc = pool->add(new MySQLTableDescriptor(tdesc)); |
542 | 91 | break; |
543 | | |
544 | 415k | case TTableType::OLAP_TABLE: |
545 | 415k | desc = pool->add(new OlapTableDescriptor(tdesc)); |
546 | 415k | break; |
547 | | |
548 | 3.39k | case TTableType::SCHEMA_TABLE: |
549 | 3.39k | desc = pool->add(new SchemaTableDescriptor(tdesc)); |
550 | 3.39k | break; |
551 | 0 | case TTableType::BROKER_TABLE: |
552 | 0 | desc = pool->add(new BrokerTableDescriptor(tdesc)); |
553 | 0 | break; |
554 | 0 | case TTableType::ES_TABLE: |
555 | 0 | desc = pool->add(new EsTableDescriptor(tdesc)); |
556 | 0 | break; |
557 | 36 | case TTableType::HIVE_TABLE: |
558 | 36 | desc = pool->add(new HiveTableDescriptor(tdesc)); |
559 | 36 | break; |
560 | 0 | case TTableType::ICEBERG_TABLE: |
561 | 0 | desc = pool->add(new IcebergTableDescriptor(tdesc)); |
562 | 0 | break; |
563 | 4 | case TTableType::JDBC_TABLE: |
564 | 4 | desc = pool->add(new JdbcTableDescriptor(tdesc)); |
565 | 4 | break; |
566 | 0 | case TTableType::MAX_COMPUTE_TABLE: |
567 | 0 | desc = pool->add(new MaxComputeTableDescriptor(tdesc)); |
568 | 0 | break; |
569 | 0 | case TTableType::TRINO_CONNECTOR_TABLE: |
570 | 0 | desc = pool->add(new TrinoConnectorTableDescriptor(tdesc)); |
571 | 0 | break; |
572 | 0 | case TTableType::DICTIONARY_TABLE: |
573 | 0 | desc = pool->add(new DictionaryTableDescriptor(tdesc)); |
574 | 0 | break; |
575 | 0 | case TTableType::REMOTE_DORIS_TABLE: |
576 | 0 | desc = pool->add(new RemoteDorisTableDescriptor(tdesc)); |
577 | 0 | break; |
578 | 0 | default: |
579 | 0 | DCHECK(false) << "invalid table type: " << tdesc.tableType; |
580 | 419k | } |
581 | | |
582 | 418k | (*tbl)->_tbl_desc_map[static_cast<int32_t>(tdesc.id)] = desc; |
583 | 418k | } |
584 | | |
585 | 1.74M | for (const auto& tdesc : thrift_tbl.tupleDescriptors) { |
586 | 1.74M | TupleDescriptor* desc = pool->add(new TupleDescriptor(tdesc)); |
587 | | |
588 | | // fix up table pointer |
589 | 1.74M | if (tdesc.__isset.tableId) { |
590 | 782k | desc->_table_desc = (*tbl)->get_table_descriptor(static_cast<int32_t>(tdesc.tableId)); |
591 | 782k | DCHECK(desc->_table_desc != nullptr); |
592 | 782k | } |
593 | | |
594 | 1.74M | (*tbl)->_tuple_desc_map[tdesc.id] = desc; |
595 | 1.74M | (*tbl)->_row_tuples.emplace_back(tdesc.id); |
596 | 1.74M | } |
597 | | |
598 | 8.60M | for (const auto& tdesc : thrift_tbl.slotDescriptors) { |
599 | 8.60M | SlotDescriptor* slot_d = pool->add(new SlotDescriptor(tdesc)); |
600 | 8.60M | (*tbl)->_slot_desc_map[tdesc.id] = slot_d; |
601 | | |
602 | | // link to parent |
603 | 8.60M | auto entry = (*tbl)->_tuple_desc_map.find(tdesc.parent); |
604 | | |
605 | 8.60M | if (entry == (*tbl)->_tuple_desc_map.end()) { |
606 | 0 | return Status::InternalError("unknown tid in slot descriptor msg"); |
607 | 0 | } |
608 | 8.60M | entry->second->add_slot(slot_d); |
609 | 8.60M | } |
610 | | |
611 | 563k | return Status::OK(); |
612 | 563k | } |
613 | | |
614 | 777k | TableDescriptor* DescriptorTbl::get_table_descriptor(TableId id) const { |
615 | | // TODO: is there some boost function to do exactly this? |
616 | 777k | auto i = _tbl_desc_map.find(id); |
617 | | |
618 | 777k | if (i == _tbl_desc_map.end()) { |
619 | 0 | return nullptr; |
620 | 777k | } else { |
621 | 777k | return i->second; |
622 | 777k | } |
623 | 777k | } |
624 | | |
625 | 2.15M | TupleDescriptor* DescriptorTbl::get_tuple_descriptor(TupleId id) const { |
626 | | // TODO: is there some boost function to do exactly this? |
627 | 2.15M | auto i = _tuple_desc_map.find(id); |
628 | | |
629 | 2.15M | if (i == _tuple_desc_map.end()) { |
630 | 695 | return nullptr; |
631 | 2.15M | } else { |
632 | 2.15M | return i->second; |
633 | 2.15M | } |
634 | 2.15M | } |
635 | | |
636 | 4.26M | SlotDescriptor* DescriptorTbl::get_slot_descriptor(SlotId id) const { |
637 | | // TODO: is there some boost function to do exactly this? |
638 | 4.26M | auto i = _slot_desc_map.find(id); |
639 | | |
640 | 4.26M | if (i == _slot_desc_map.end()) { |
641 | 0 | return nullptr; |
642 | 4.26M | } else { |
643 | 4.26M | return i->second; |
644 | 4.26M | } |
645 | 4.26M | } |
646 | | |
647 | 0 | std::string DescriptorTbl::debug_string() const { |
648 | 0 | std::stringstream out; |
649 | 0 | out << "tuples:\n"; |
650 | |
|
651 | 0 | for (auto i : _tuple_desc_map) { |
652 | 0 | out << i.second->debug_string() << '\n'; |
653 | 0 | } |
654 | |
|
655 | 0 | return out.str(); |
656 | 0 | } |
657 | | } // namespace doris |