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