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 | 768k | : _id(tdesc.id), |
53 | 768k | _type(DataTypeFactory::instance().create_data_type(tdesc.slotType, |
54 | 768k | tdesc.nullIndicatorBit != -1)), |
55 | 768k | _parent(tdesc.parent), |
56 | 768k | _col_pos(tdesc.columnPos), |
57 | 768k | _col_name(tdesc.colName), |
58 | 768k | _col_name_lower_case(to_lower(tdesc.colName)), |
59 | 768k | _col_unique_id(tdesc.col_unique_id), |
60 | 768k | _slot_idx(tdesc.slotIdx), |
61 | 768k | _field_idx(-1), |
62 | 768k | _is_key(tdesc.is_key), |
63 | 768k | _column_paths(tdesc.column_paths), |
64 | 768k | _all_access_paths(tdesc.__isset.all_access_paths ? tdesc.all_access_paths |
65 | 768k | : TColumnAccessPaths {}), |
66 | 768k | _predicate_access_paths(tdesc.__isset.predicate_access_paths |
67 | 768k | ? tdesc.predicate_access_paths |
68 | 768k | : TColumnAccessPaths {}), |
69 | 18.4E | _is_auto_increment(tdesc.__isset.is_auto_increment ? tdesc.is_auto_increment : false), |
70 | 768k | _col_default_value(tdesc.__isset.col_default_value ? tdesc.col_default_value : "") { |
71 | 768k | if (tdesc.__isset.virtual_column_expr) { |
72 | | // Make sure virtual column is valid. |
73 | 100 | 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 | 98 | const auto& node = tdesc.virtual_column_expr.nodes[0]; |
80 | 98 | 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 | 96 | this->virtual_column_expr = std::make_shared<doris::TExpr>(tdesc.virtual_column_expr); |
87 | 96 | } |
88 | 768k | } |
89 | | |
90 | | SlotDescriptor::SlotDescriptor(const PSlotDescriptor& pdesc) |
91 | 84 | : _id(pdesc.id()), |
92 | 84 | _type(DataTypeFactory::instance().create_data_type(pdesc.slot_type(), |
93 | 84 | pdesc.null_indicator_bit() != -1)), |
94 | 84 | _parent(pdesc.parent()), |
95 | 84 | _col_pos(pdesc.column_pos()), |
96 | 84 | _col_name(pdesc.col_name()), |
97 | 84 | _col_name_lower_case(to_lower(pdesc.col_name())), |
98 | 84 | _col_unique_id(pdesc.col_unique_id()), |
99 | 84 | _slot_idx(pdesc.slot_idx()), |
100 | 84 | _field_idx(-1), |
101 | 84 | _is_key(pdesc.is_key()), |
102 | 84 | _column_paths(pdesc.column_paths().begin(), pdesc.column_paths().end()), |
103 | 84 | _is_auto_increment(pdesc.is_auto_increment()) { |
104 | 84 | auto convert_to_thrift_column_access_path = [](const PColumnAccessPath& pb_path) { |
105 | 0 | TColumnAccessPath thrift_path; |
106 | 0 | thrift_path.type = (TAccessPathType::type)pb_path.type(); |
107 | 0 | if (pb_path.has_data_access_path()) { |
108 | 0 | thrift_path.__isset.data_access_path = true; |
109 | 0 | for (int i = 0; i < pb_path.data_access_path().path_size(); ++i) { |
110 | 0 | thrift_path.data_access_path.path.push_back(pb_path.data_access_path().path(i)); |
111 | 0 | } |
112 | 0 | } |
113 | 0 | 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 | 0 | return thrift_path; |
120 | 0 | }; |
121 | 84 | for (const auto& pb_path : pdesc.all_access_paths()) { |
122 | 0 | _all_access_paths.push_back(convert_to_thrift_column_access_path(pb_path)); |
123 | 0 | } |
124 | 84 | 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 | 84 | } |
128 | | |
129 | | #ifdef BE_TEST |
130 | | SlotDescriptor::SlotDescriptor() |
131 | 364 | : _id(0), |
132 | 364 | _type(nullptr), |
133 | 364 | _parent(0), |
134 | 364 | _col_pos(0), |
135 | 364 | _col_unique_id(0), |
136 | 364 | _slot_idx(0), |
137 | 364 | _field_idx(-1), |
138 | 364 | _is_key(false), |
139 | 364 | _is_auto_increment(false) {} |
140 | | #endif |
141 | | |
142 | 96 | void SlotDescriptor::to_protobuf(PSlotDescriptor* pslot) const { |
143 | 96 | pslot->set_id(_id); |
144 | 96 | pslot->set_parent(_parent); |
145 | 96 | _type->to_protobuf(pslot->mutable_slot_type()); |
146 | 96 | pslot->set_column_pos(_col_pos); |
147 | 96 | pslot->set_byte_offset(0); |
148 | 96 | pslot->set_null_indicator_byte(0); |
149 | 96 | pslot->set_null_indicator_bit(_type->is_nullable() ? 0 : -1); |
150 | 96 | pslot->set_col_name(_col_name); |
151 | 96 | pslot->set_slot_idx(_slot_idx); |
152 | 96 | pslot->set_col_unique_id(_col_unique_id); |
153 | 96 | pslot->set_is_key(_is_key); |
154 | 96 | pslot->set_is_auto_increment(_is_auto_increment); |
155 | 96 | pslot->set_col_type(_type->get_primitive_type()); |
156 | 96 | for (const std::string& path : _column_paths) { |
157 | 0 | pslot->add_column_paths(path); |
158 | 0 | } |
159 | 96 | auto convert_to_protobuf_column_access_path = [](const TColumnAccessPath& thrift_path, |
160 | 96 | doris::PColumnAccessPath* pb_path) { |
161 | 0 | pb_path->Clear(); |
162 | 0 | pb_path->set_type((PAccessPathType)thrift_path.type); // 使用 reinterpret_cast 进行类型转换 |
163 | 0 | if (thrift_path.__isset.data_access_path) { |
164 | 0 | auto* pb_data = pb_path->mutable_data_access_path(); |
165 | 0 | pb_data->Clear(); |
166 | 0 | for (const auto& s : thrift_path.data_access_path.path) { |
167 | 0 | pb_data->add_path(s); |
168 | 0 | } |
169 | 0 | } |
170 | 0 | 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 | 0 | }; |
178 | 96 | for (const auto& path : _all_access_paths) { |
179 | 0 | auto* pb_path = pslot->add_all_access_paths(); |
180 | 0 | convert_to_protobuf_column_access_path(path, pb_path); |
181 | 0 | } |
182 | 96 | 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 | 96 | } |
187 | | |
188 | 748k | DataTypePtr SlotDescriptor::get_data_type_ptr() const { |
189 | 748k | return get_data_type_with_default_argument(type()); |
190 | 748k | } |
191 | | |
192 | 271k | MutableColumnPtr SlotDescriptor::get_empty_mutable_column() const { |
193 | 271k | if (this->get_virtual_column_expr() != nullptr) { |
194 | 0 | return ColumnNothing::create(0); |
195 | 0 | } |
196 | | |
197 | 271k | return type()->create_column(); |
198 | 271k | } |
199 | | |
200 | 342 | bool SlotDescriptor::is_nullable() const { |
201 | 342 | return _type->is_nullable(); |
202 | 342 | } |
203 | | |
204 | 821 | PrimitiveType SlotDescriptor::col_type() const { |
205 | 821 | return _type->get_primitive_type(); |
206 | 821 | } |
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 | 218 | : _table_type(tdesc.tableType), |
218 | 218 | _name(tdesc.tableName), |
219 | 218 | _database(tdesc.dbName), |
220 | 218 | _table_id(tdesc.id), |
221 | 218 | _num_cols(tdesc.numCols), |
222 | 218 | _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 | 95 | 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 | 0 | : TableDescriptor(tdesc), _schema_table_type(tdesc.schemaTable.tableType) {} |
249 | 0 | 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 | 87 | : TableDescriptor(tdesc), |
354 | 87 | _mysql_db(tdesc.mysqlTable.db), |
355 | 87 | _mysql_table(tdesc.mysqlTable.table), |
356 | 87 | _host(tdesc.mysqlTable.host), |
357 | 87 | _port(tdesc.mysqlTable.port), |
358 | 87 | _user(tdesc.mysqlTable.user), |
359 | 87 | _passwd(tdesc.mysqlTable.passwd), |
360 | 87 | _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 | | FilesetTableDescriptor::FilesetTableDescriptor(const TTableDescriptor& tdesc) |
405 | 0 | : TableDescriptor(tdesc), |
406 | 0 | _table_path(tdesc.filesetTable.table_path), |
407 | 0 | _file_type(tdesc.filesetTable.file_type), |
408 | 0 | _properties(tdesc.filesetTable.properties) {} |
409 | | |
410 | 0 | std::string FilesetTableDescriptor::debug_string() const { |
411 | 0 | return fmt::format("FilesetTable({} table_path={}, file_type={})", |
412 | 0 | TableDescriptor::debug_string(), _table_path, static_cast<int>(_file_type)); |
413 | 0 | } |
414 | | |
415 | | RemoteDorisTableDescriptor::RemoteDorisTableDescriptor(const TTableDescriptor& tdesc) |
416 | 0 | : TableDescriptor(tdesc) {} |
417 | | |
418 | 0 | RemoteDorisTableDescriptor::~RemoteDorisTableDescriptor() = default; |
419 | | |
420 | 0 | std::string RemoteDorisTableDescriptor::debug_string() const { |
421 | 0 | std::stringstream out; |
422 | 0 | out << "RemoteDorisTable(" << TableDescriptor::debug_string() << ")"; |
423 | 0 | return out.str(); |
424 | 0 | } |
425 | | |
426 | | TupleDescriptor::TupleDescriptor(const TTupleDescriptor& tdesc, bool own_slots) |
427 | 292k | : _id(tdesc.id), |
428 | 292k | _num_materialized_slots(0), |
429 | 292k | _has_varlen_slots(false), |
430 | 292k | _own_slots(own_slots) {} |
431 | | |
432 | | TupleDescriptor::TupleDescriptor(const PTupleDescriptor& pdesc, bool own_slots) |
433 | 18 | : _id(pdesc.id()), |
434 | 18 | _num_materialized_slots(0), |
435 | 18 | _has_varlen_slots(false), |
436 | 18 | _own_slots(own_slots) {} |
437 | | |
438 | 768k | void TupleDescriptor::add_slot(SlotDescriptor* slot) { |
439 | 768k | _slots.push_back(slot); |
440 | 768k | ++_num_materialized_slots; |
441 | | |
442 | 768k | if (is_complex_type(slot->type()->get_primitive_type()) || |
443 | 768k | is_var_len_object(slot->type()->get_primitive_type()) || |
444 | 768k | is_string_type(slot->type()->get_primitive_type())) { |
445 | 129k | _has_varlen_slots = true; |
446 | 129k | } |
447 | 768k | } |
448 | | |
449 | 16 | void TupleDescriptor::to_protobuf(PTupleDescriptor* ptuple) const { |
450 | 16 | ptuple->Clear(); |
451 | 16 | ptuple->set_id(_id); |
452 | | // Useless not set |
453 | 16 | ptuple->set_byte_size(0); |
454 | 16 | ptuple->set_table_id(-1); |
455 | 16 | ptuple->set_num_null_bytes(0); |
456 | 16 | } |
457 | | |
458 | 2 | std::string TupleDescriptor::debug_string() const { |
459 | 2 | std::stringstream out; |
460 | 2 | out << "Tuple(id=" << _id; |
461 | 2 | if (_table_desc != nullptr) { |
462 | | //out << " " << _table_desc->debug_string(); |
463 | 0 | } |
464 | | |
465 | 2 | out << " slots=["; |
466 | 8 | for (size_t i = 0; i < _slots.size(); ++i) { |
467 | 6 | if (i > 0) { |
468 | 4 | out << ", "; |
469 | 4 | } |
470 | 6 | out << _slots[i]->debug_string(); |
471 | 6 | } |
472 | | |
473 | 2 | out << "]"; |
474 | 2 | out << " has_varlen_slots=" << _has_varlen_slots; |
475 | 2 | out << ")"; |
476 | 2 | return out.str(); |
477 | 2 | } |
478 | | |
479 | | RowDescriptor::RowDescriptor(const DescriptorTbl& desc_tbl, |
480 | 360k | const std::vector<TTupleId>& row_tuples) { |
481 | 360k | DCHECK_GT(row_tuples.size(), 0); |
482 | 360k | _num_materialized_slots = 0; |
483 | 360k | _num_slots = 0; |
484 | | |
485 | 433k | for (int row_tuple : row_tuples) { |
486 | 433k | TupleDescriptor* tupleDesc = desc_tbl.get_tuple_descriptor(row_tuple); |
487 | 433k | _num_materialized_slots += tupleDesc->num_materialized_slots(); |
488 | 433k | _num_slots += tupleDesc->slots().size(); |
489 | 433k | _tuple_desc_map.push_back(tupleDesc); |
490 | 433k | DCHECK(_tuple_desc_map.back() != nullptr); |
491 | 433k | } |
492 | | |
493 | 360k | init_tuple_idx_map(); |
494 | 360k | init_has_varlen_slots(); |
495 | 360k | } |
496 | | |
497 | 4.10k | RowDescriptor::RowDescriptor(TupleDescriptor* tuple_desc) : _tuple_desc_map(1, tuple_desc) { |
498 | 4.10k | init_tuple_idx_map(); |
499 | 4.10k | init_has_varlen_slots(); |
500 | 4.10k | _num_slots = static_cast<int32_t>(tuple_desc->slots().size()); |
501 | 4.10k | } |
502 | | |
503 | 0 | RowDescriptor::RowDescriptor(const RowDescriptor& lhs_row_desc, const RowDescriptor& rhs_row_desc) { |
504 | 0 | _tuple_desc_map.insert(_tuple_desc_map.end(), lhs_row_desc._tuple_desc_map.begin(), |
505 | 0 | lhs_row_desc._tuple_desc_map.end()); |
506 | 0 | _tuple_desc_map.insert(_tuple_desc_map.end(), rhs_row_desc._tuple_desc_map.begin(), |
507 | 0 | rhs_row_desc._tuple_desc_map.end()); |
508 | 0 | init_tuple_idx_map(); |
509 | 0 | init_has_varlen_slots(); |
510 | |
|
511 | 0 | _num_slots = lhs_row_desc.num_slots() + rhs_row_desc.num_slots(); |
512 | 0 | } |
513 | | |
514 | 365k | void RowDescriptor::init_tuple_idx_map() { |
515 | | // find max id |
516 | 365k | TupleId max_id = 0; |
517 | 437k | for (auto& i : _tuple_desc_map) { |
518 | 437k | max_id = std::max(i->id(), max_id); |
519 | 437k | } |
520 | | |
521 | 365k | _tuple_idx_map.resize(max_id + 1, INVALID_IDX); |
522 | 802k | for (int i = 0; i < _tuple_desc_map.size(); ++i) { |
523 | 437k | _tuple_idx_map[_tuple_desc_map[i]->id()] = i; |
524 | 437k | } |
525 | 365k | } |
526 | | |
527 | 365k | void RowDescriptor::init_has_varlen_slots() { |
528 | 365k | _has_varlen_slots = false; |
529 | 415k | for (auto& i : _tuple_desc_map) { |
530 | 415k | if (i->has_varlen_slots()) { |
531 | 112k | _has_varlen_slots = true; |
532 | 112k | break; |
533 | 112k | } |
534 | 415k | } |
535 | 365k | } |
536 | | |
537 | 0 | int RowDescriptor::get_tuple_idx(TupleId id) const { |
538 | | // comment CHECK temporarily to make fuzzy test run smoothly |
539 | | // DCHECK_LT(id, _tuple_idx_map.size()) << "RowDescriptor: " << debug_string(); |
540 | 0 | if (_tuple_idx_map.size() <= id) { |
541 | 0 | return RowDescriptor::INVALID_IDX; |
542 | 0 | } |
543 | 0 | return _tuple_idx_map[id]; |
544 | 0 | } |
545 | | |
546 | 0 | void RowDescriptor::to_thrift(std::vector<TTupleId>* row_tuple_ids) { |
547 | 0 | row_tuple_ids->clear(); |
548 | |
|
549 | 0 | for (auto& i : _tuple_desc_map) { |
550 | 0 | row_tuple_ids->push_back(i->id()); |
551 | 0 | } |
552 | 0 | } |
553 | | |
554 | | void RowDescriptor::to_protobuf( |
555 | 0 | google::protobuf::RepeatedField<google::protobuf::int32>* row_tuple_ids) const { |
556 | 0 | row_tuple_ids->Clear(); |
557 | 0 | for (auto* desc : _tuple_desc_map) { |
558 | 0 | row_tuple_ids->Add(desc->id()); |
559 | 0 | } |
560 | 0 | } |
561 | | |
562 | 0 | bool RowDescriptor::is_prefix_of(const RowDescriptor& other_desc) const { |
563 | 0 | if (_tuple_desc_map.size() > other_desc._tuple_desc_map.size()) { |
564 | 0 | return false; |
565 | 0 | } |
566 | | |
567 | 0 | for (int i = 0; i < _tuple_desc_map.size(); ++i) { |
568 | | // pointer comparison okay, descriptors are unique |
569 | 0 | if (_tuple_desc_map[i] != other_desc._tuple_desc_map[i]) { |
570 | 0 | return false; |
571 | 0 | } |
572 | 0 | } |
573 | | |
574 | 0 | return true; |
575 | 0 | } |
576 | | |
577 | 0 | bool RowDescriptor::equals(const RowDescriptor& other_desc) const { |
578 | 0 | if (_tuple_desc_map.size() != other_desc._tuple_desc_map.size()) { |
579 | 0 | return false; |
580 | 0 | } |
581 | | |
582 | 0 | for (int i = 0; i < _tuple_desc_map.size(); ++i) { |
583 | | // pointer comparison okay, descriptors are unique |
584 | 0 | if (_tuple_desc_map[i] != other_desc._tuple_desc_map[i]) { |
585 | 0 | return false; |
586 | 0 | } |
587 | 0 | } |
588 | | |
589 | 0 | return true; |
590 | 0 | } |
591 | | |
592 | 0 | std::string RowDescriptor::debug_string() const { |
593 | 0 | std::stringstream ss; |
594 | |
|
595 | 0 | ss << "tuple_desc_map: ["; |
596 | 0 | for (int i = 0; i < _tuple_desc_map.size(); ++i) { |
597 | 0 | ss << _tuple_desc_map[i]->debug_string(); |
598 | 0 | if (i != _tuple_desc_map.size() - 1) { |
599 | 0 | ss << ", "; |
600 | 0 | } |
601 | 0 | } |
602 | 0 | ss << "] "; |
603 | |
|
604 | 0 | ss << "tuple_id_map: ["; |
605 | 0 | for (int i = 0; i < _tuple_idx_map.size(); ++i) { |
606 | 0 | ss << _tuple_idx_map[i]; |
607 | 0 | if (i != _tuple_idx_map.size() - 1) { |
608 | 0 | ss << ", "; |
609 | 0 | } |
610 | 0 | } |
611 | 0 | ss << "] "; |
612 | |
|
613 | 0 | return ss.str(); |
614 | 0 | } |
615 | | |
616 | 258k | int RowDescriptor::get_column_id(int slot_id) const { |
617 | 258k | int column_id_counter = 0; |
618 | 258k | for (auto* const tuple_desc : _tuple_desc_map) { |
619 | 420k | for (auto* const slot : tuple_desc->slots()) { |
620 | 420k | if (slot->id() == slot_id) { |
621 | 258k | return column_id_counter; |
622 | 258k | } |
623 | 162k | column_id_counter++; |
624 | 162k | } |
625 | 258k | } |
626 | 96 | return -1; |
627 | 258k | } |
628 | | |
629 | | Status DescriptorTbl::create(ObjectPool* pool, const TDescriptorTable& thrift_tbl, |
630 | 76.4k | DescriptorTbl** tbl) { |
631 | 76.4k | *tbl = pool->add(new DescriptorTbl()); |
632 | | |
633 | | // deserialize table descriptors first, they are being referenced by tuple descriptors |
634 | 76.4k | for (const auto& tdesc : thrift_tbl.tableDescriptors) { |
635 | 218 | TableDescriptor* desc = nullptr; |
636 | | |
637 | 218 | switch (tdesc.tableType) { |
638 | 87 | case TTableType::MYSQL_TABLE: |
639 | 87 | desc = pool->add(new MySQLTableDescriptor(tdesc)); |
640 | 87 | break; |
641 | | |
642 | 95 | case TTableType::OLAP_TABLE: |
643 | 95 | desc = pool->add(new OlapTableDescriptor(tdesc)); |
644 | 95 | break; |
645 | | |
646 | 0 | case TTableType::SCHEMA_TABLE: |
647 | 0 | desc = pool->add(new SchemaTableDescriptor(tdesc)); |
648 | 0 | break; |
649 | 0 | case TTableType::BROKER_TABLE: |
650 | 0 | desc = pool->add(new BrokerTableDescriptor(tdesc)); |
651 | 0 | break; |
652 | 0 | case TTableType::ES_TABLE: |
653 | 0 | desc = pool->add(new EsTableDescriptor(tdesc)); |
654 | 0 | break; |
655 | 36 | case TTableType::HIVE_TABLE: |
656 | 36 | desc = pool->add(new HiveTableDescriptor(tdesc)); |
657 | 36 | break; |
658 | 0 | case TTableType::ICEBERG_TABLE: |
659 | 0 | desc = pool->add(new IcebergTableDescriptor(tdesc)); |
660 | 0 | break; |
661 | 0 | case TTableType::JDBC_TABLE: |
662 | 0 | desc = pool->add(new JdbcTableDescriptor(tdesc)); |
663 | 0 | break; |
664 | 0 | case TTableType::FILESET_TABLE: |
665 | 0 | desc = pool->add(new FilesetTableDescriptor(tdesc)); |
666 | 0 | break; |
667 | 0 | case TTableType::MAX_COMPUTE_TABLE: |
668 | 0 | desc = pool->add(new MaxComputeTableDescriptor(tdesc)); |
669 | 0 | break; |
670 | 0 | case TTableType::TRINO_CONNECTOR_TABLE: |
671 | 0 | desc = pool->add(new TrinoConnectorTableDescriptor(tdesc)); |
672 | 0 | break; |
673 | 0 | case TTableType::DICTIONARY_TABLE: |
674 | 0 | desc = pool->add(new DictionaryTableDescriptor(tdesc)); |
675 | 0 | break; |
676 | 0 | case TTableType::REMOTE_DORIS_TABLE: |
677 | 0 | desc = pool->add(new RemoteDorisTableDescriptor(tdesc)); |
678 | 0 | break; |
679 | 0 | default: |
680 | 0 | DCHECK(false) << "invalid table type: " << tdesc.tableType; |
681 | 218 | } |
682 | | |
683 | 218 | (*tbl)->_tbl_desc_map[static_cast<int32_t>(tdesc.id)] = desc; |
684 | 218 | } |
685 | | |
686 | 292k | for (const auto& tdesc : thrift_tbl.tupleDescriptors) { |
687 | 292k | TupleDescriptor* desc = pool->add(new TupleDescriptor(tdesc)); |
688 | | |
689 | | // fix up table pointer |
690 | 292k | if (tdesc.__isset.tableId) { |
691 | 190 | desc->_table_desc = (*tbl)->get_table_descriptor(static_cast<int32_t>(tdesc.tableId)); |
692 | 190 | DCHECK(desc->_table_desc != nullptr); |
693 | 190 | } |
694 | | |
695 | 292k | (*tbl)->_tuple_desc_map[tdesc.id] = desc; |
696 | 292k | (*tbl)->_row_tuples.emplace_back(tdesc.id); |
697 | 292k | } |
698 | | |
699 | 768k | for (const auto& tdesc : thrift_tbl.slotDescriptors) { |
700 | 768k | SlotDescriptor* slot_d = pool->add(new SlotDescriptor(tdesc)); |
701 | 768k | (*tbl)->_slot_desc_map[tdesc.id] = slot_d; |
702 | | |
703 | | // link to parent |
704 | 768k | auto entry = (*tbl)->_tuple_desc_map.find(tdesc.parent); |
705 | | |
706 | 768k | if (entry == (*tbl)->_tuple_desc_map.end()) { |
707 | 0 | return Status::InternalError("unknown tid in slot descriptor msg"); |
708 | 0 | } |
709 | 768k | entry->second->add_slot(slot_d); |
710 | 768k | } |
711 | | |
712 | 76.4k | return Status::OK(); |
713 | 76.4k | } |
714 | | |
715 | 190 | TableDescriptor* DescriptorTbl::get_table_descriptor(TableId id) const { |
716 | | // TODO: is there some boost function to do exactly this? |
717 | 190 | auto i = _tbl_desc_map.find(id); |
718 | | |
719 | 190 | if (i == _tbl_desc_map.end()) { |
720 | 0 | return nullptr; |
721 | 190 | } else { |
722 | 190 | return i->second; |
723 | 190 | } |
724 | 190 | } |
725 | | |
726 | 639k | TupleDescriptor* DescriptorTbl::get_tuple_descriptor(TupleId id) const { |
727 | | // TODO: is there some boost function to do exactly this? |
728 | 639k | auto i = _tuple_desc_map.find(id); |
729 | | |
730 | 639k | if (i == _tuple_desc_map.end()) { |
731 | 3 | return nullptr; |
732 | 639k | } else { |
733 | 639k | return i->second; |
734 | 639k | } |
735 | 639k | } |
736 | | |
737 | 258k | SlotDescriptor* DescriptorTbl::get_slot_descriptor(SlotId id) const { |
738 | | // TODO: is there some boost function to do exactly this? |
739 | 258k | auto i = _slot_desc_map.find(id); |
740 | | |
741 | 258k | if (i == _slot_desc_map.end()) { |
742 | 0 | return nullptr; |
743 | 258k | } else { |
744 | 258k | return i->second; |
745 | 258k | } |
746 | 258k | } |
747 | | |
748 | 0 | std::string DescriptorTbl::debug_string() const { |
749 | 0 | std::stringstream out; |
750 | 0 | out << "tuples:\n"; |
751 | |
|
752 | 0 | for (auto i : _tuple_desc_map) { |
753 | 0 | out << i.second->debug_string() << '\n'; |
754 | 0 | } |
755 | |
|
756 | 0 | return out.str(); |
757 | 0 | } |
758 | | } // namespace doris |