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