Coverage Report

Created: 2024-11-18 11:49

/root/doris/be/src/runtime/descriptors.cpp
Line
Count
Source (jump to first uncovered line)
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
29
#include <algorithm>
30
#include <boost/algorithm/string/join.hpp>
31
#include <memory>
32
33
#include "common/object_pool.h"
34
#include "runtime/primitive_type.h"
35
#include "util/string_util.h"
36
#include "vec/aggregate_functions/aggregate_function.h"
37
#include "vec/data_types/data_type_factory.hpp"
38
39
namespace doris {
40
41
const int RowDescriptor::INVALID_IDX = -1;
42
43
SlotDescriptor::SlotDescriptor(const TSlotDescriptor& tdesc)
44
        : _id(tdesc.id),
45
          _type(TypeDescriptor::from_thrift(tdesc.slotType)),
46
          _parent(tdesc.parent),
47
          _col_pos(tdesc.columnPos),
48
          _is_nullable(tdesc.nullIndicatorBit != -1),
49
          _col_name(tdesc.colName),
50
          _col_name_lower_case(to_lower(tdesc.colName)),
51
          _col_unique_id(tdesc.col_unique_id),
52
          _col_type(thrift_to_type(tdesc.primitive_type)),
53
          _slot_idx(tdesc.slotIdx),
54
          _field_idx(-1),
55
          _is_materialized(tdesc.isMaterialized),
56
          _is_key(tdesc.is_key),
57
          _need_materialize(tdesc.need_materialize),
58
          _column_paths(tdesc.column_paths),
59
          _is_auto_increment(tdesc.__isset.is_auto_increment ? tdesc.is_auto_increment : false),
60
251
          _col_default_value(tdesc.__isset.col_default_value ? tdesc.col_default_value : "") {}
61
62
SlotDescriptor::SlotDescriptor(const PSlotDescriptor& pdesc)
63
        : _id(pdesc.id()),
64
          _type(TypeDescriptor::from_protobuf(pdesc.slot_type())),
65
          _parent(pdesc.parent()),
66
          _col_pos(pdesc.column_pos()),
67
          _is_nullable(pdesc.null_indicator_bit() != -1),
68
          _col_name(pdesc.col_name()),
69
          _col_name_lower_case(to_lower(pdesc.col_name())),
70
          _col_unique_id(pdesc.col_unique_id()),
71
          _col_type(static_cast<PrimitiveType>(pdesc.col_type())),
72
          _slot_idx(pdesc.slot_idx()),
73
          _field_idx(-1),
74
          _is_materialized(pdesc.is_materialized()),
75
          _is_key(pdesc.is_key()),
76
          _need_materialize(true),
77
          _column_paths(pdesc.column_paths().begin(), pdesc.column_paths().end()),
78
84
          _is_auto_increment(pdesc.is_auto_increment()) {}
79
80
96
void SlotDescriptor::to_protobuf(PSlotDescriptor* pslot) const {
81
96
    pslot->set_id(_id);
82
96
    pslot->set_parent(_parent);
83
96
    _type.to_protobuf(pslot->mutable_slot_type());
84
96
    pslot->set_column_pos(_col_pos);
85
96
    pslot->set_byte_offset(0);
86
96
    pslot->set_null_indicator_byte(0);
87
96
    pslot->set_null_indicator_bit(_is_nullable ? 0 : -1);
88
96
    pslot->set_col_name(_col_name);
89
96
    pslot->set_slot_idx(_slot_idx);
90
96
    pslot->set_is_materialized(_is_materialized);
91
96
    pslot->set_col_unique_id(_col_unique_id);
92
96
    pslot->set_is_key(_is_key);
93
96
    pslot->set_is_auto_increment(_is_auto_increment);
94
96
    pslot->set_col_type(_col_type);
95
96
    for (const std::string& path : _column_paths) {
96
0
        pslot->add_column_paths(path);
97
0
    }
98
96
}
99
100
77
vectorized::MutableColumnPtr SlotDescriptor::get_empty_mutable_column() const {
101
77
    auto data_type = get_data_type_ptr();
102
77
    if (data_type) {
103
77
        return data_type->create_column();
104
77
    }
105
0
    return nullptr;
106
77
}
107
108
190
vectorized::DataTypePtr SlotDescriptor::get_data_type_ptr() const {
109
190
    return vectorized::DataTypeFactory::instance().create_data_type(type(), is_nullable());
110
190
}
111
112
0
std::string SlotDescriptor::debug_string() const {
113
0
    std::stringstream out;
114
0
    out << "Slot(id=" << _id << " type=" << _type << " col=" << _col_pos
115
0
        << ", colname=" << _col_name << ", nullable=" << is_nullable() << ")";
116
0
    return out.str();
117
0
}
118
119
TableDescriptor::TableDescriptor(const TTableDescriptor& tdesc)
120
        : _table_type(tdesc.tableType),
121
          _name(tdesc.tableName),
122
          _database(tdesc.dbName),
123
          _table_id(tdesc.id),
124
          _num_cols(tdesc.numCols),
125
4
          _num_clustering_cols(tdesc.numClusteringCols) {}
126
127
0
std::string TableDescriptor::debug_string() const {
128
0
    std::stringstream out;
129
0
    out << "#cols=" << _num_cols << " #clustering_cols=" << _num_clustering_cols;
130
0
    return out.str();
131
0
}
132
133
4
OlapTableDescriptor::OlapTableDescriptor(const TTableDescriptor& tdesc) : TableDescriptor(tdesc) {}
134
135
0
std::string OlapTableDescriptor::debug_string() const {
136
0
    std::stringstream out;
137
0
    out << "OlapTable(" << TableDescriptor::debug_string() << ")";
138
0
    return out.str();
139
0
}
140
141
SchemaTableDescriptor::SchemaTableDescriptor(const TTableDescriptor& tdesc)
142
0
        : TableDescriptor(tdesc), _schema_table_type(tdesc.schemaTable.tableType) {}
143
0
SchemaTableDescriptor::~SchemaTableDescriptor() = default;
144
145
0
std::string SchemaTableDescriptor::debug_string() const {
146
0
    std::stringstream out;
147
0
    out << "SchemaTable(" << TableDescriptor::debug_string() << ")";
148
0
    return out.str();
149
0
}
150
151
BrokerTableDescriptor::BrokerTableDescriptor(const TTableDescriptor& tdesc)
152
0
        : TableDescriptor(tdesc) {}
153
154
0
BrokerTableDescriptor::~BrokerTableDescriptor() = default;
155
156
0
std::string BrokerTableDescriptor::debug_string() const {
157
0
    std::stringstream out;
158
0
    out << "BrokerTable(" << TableDescriptor::debug_string() << ")";
159
0
    return out.str();
160
0
}
161
162
0
HiveTableDescriptor::HiveTableDescriptor(const TTableDescriptor& tdesc) : TableDescriptor(tdesc) {}
163
164
0
HiveTableDescriptor::~HiveTableDescriptor() = default;
165
166
0
std::string HiveTableDescriptor::debug_string() const {
167
0
    std::stringstream out;
168
0
    out << "HiveTable(" << TableDescriptor::debug_string() << ")";
169
0
    return out.str();
170
0
}
171
172
IcebergTableDescriptor::IcebergTableDescriptor(const TTableDescriptor& tdesc)
173
0
        : TableDescriptor(tdesc) {}
174
175
0
IcebergTableDescriptor::~IcebergTableDescriptor() = default;
176
177
0
std::string IcebergTableDescriptor::debug_string() const {
178
0
    std::stringstream out;
179
0
    out << "IcebergTable(" << TableDescriptor::debug_string() << ")";
180
0
    return out.str();
181
0
}
182
183
MaxComputeTableDescriptor::MaxComputeTableDescriptor(const TTableDescriptor& tdesc)
184
        : TableDescriptor(tdesc),
185
          _region(tdesc.mcTable.region),
186
          _project(tdesc.mcTable.project),
187
          _table(tdesc.mcTable.table),
188
          _odps_url(tdesc.mcTable.odps_url),
189
          _tunnel_url(tdesc.mcTable.tunnel_url),
190
          _access_key(tdesc.mcTable.access_key),
191
          _secret_key(tdesc.mcTable.secret_key),
192
0
          _public_access(tdesc.mcTable.public_access) {
193
0
    if (tdesc.mcTable.__isset.endpoint) {
194
0
        _endpoint = tdesc.mcTable.endpoint;
195
0
    } else {
196
0
        _init_status = Status::InvalidArgument(
197
0
                "fail to init MaxComputeTableDescriptor, missing endpoint.");
198
0
    }
199
200
0
    if (tdesc.mcTable.__isset.quota) {
201
0
        _quota = tdesc.mcTable.quota;
202
0
    } else {
203
0
        _init_status =
204
0
                Status::InvalidArgument("fail to init MaxComputeTableDescriptor, missing quota.");
205
0
    }
206
0
}
207
208
0
MaxComputeTableDescriptor::~MaxComputeTableDescriptor() = default;
209
210
0
std::string MaxComputeTableDescriptor::debug_string() const {
211
0
    std::stringstream out;
212
0
    out << "MaxComputeTable(" << TableDescriptor::debug_string() << ")";
213
0
    return out.str();
214
0
}
215
216
TrinoConnectorTableDescriptor::TrinoConnectorTableDescriptor(const TTableDescriptor& tdesc)
217
0
        : TableDescriptor(tdesc) {}
218
219
0
TrinoConnectorTableDescriptor::~TrinoConnectorTableDescriptor() = default;
220
221
0
std::string TrinoConnectorTableDescriptor::debug_string() const {
222
0
    std::stringstream out;
223
0
    out << "TrinoConnectorTable(" << TableDescriptor::debug_string() << ")";
224
0
    return out.str();
225
0
}
226
227
0
EsTableDescriptor::EsTableDescriptor(const TTableDescriptor& tdesc) : TableDescriptor(tdesc) {}
228
229
0
EsTableDescriptor::~EsTableDescriptor() = default;
230
231
0
std::string EsTableDescriptor::debug_string() const {
232
0
    std::stringstream out;
233
0
    out << "EsTable(" << TableDescriptor::debug_string() << ")";
234
0
    return out.str();
235
0
}
236
237
MySQLTableDescriptor::MySQLTableDescriptor(const TTableDescriptor& tdesc)
238
        : TableDescriptor(tdesc),
239
          _mysql_db(tdesc.mysqlTable.db),
240
          _mysql_table(tdesc.mysqlTable.table),
241
          _host(tdesc.mysqlTable.host),
242
          _port(tdesc.mysqlTable.port),
243
          _user(tdesc.mysqlTable.user),
244
          _passwd(tdesc.mysqlTable.passwd),
245
0
          _charset(tdesc.mysqlTable.charset) {}
246
247
0
std::string MySQLTableDescriptor::debug_string() const {
248
0
    std::stringstream out;
249
0
    out << "MySQLTable(" << TableDescriptor::debug_string() << " _db" << _mysql_db
250
0
        << " table=" << _mysql_table << " host=" << _host << " port=" << _port << " user=" << _user
251
0
        << " passwd=" << _passwd << " charset=" << _charset;
252
0
    return out.str();
253
0
}
254
255
ODBCTableDescriptor::ODBCTableDescriptor(const TTableDescriptor& tdesc)
256
        : TableDescriptor(tdesc),
257
          _db(tdesc.odbcTable.db),
258
          _table(tdesc.odbcTable.table),
259
          _host(tdesc.odbcTable.host),
260
          _port(tdesc.odbcTable.port),
261
          _user(tdesc.odbcTable.user),
262
          _passwd(tdesc.odbcTable.passwd),
263
          _driver(tdesc.odbcTable.driver),
264
0
          _type(tdesc.odbcTable.type) {}
265
266
0
std::string ODBCTableDescriptor::debug_string() const {
267
0
    std::stringstream out;
268
0
    out << "ODBCTable(" << TableDescriptor::debug_string() << " _db" << _db << " table=" << _table
269
0
        << " host=" << _host << " port=" << _port << " user=" << _user << " passwd=" << _passwd
270
0
        << " driver=" << _driver << " type" << _type;
271
0
    return out.str();
272
0
}
273
274
JdbcTableDescriptor::JdbcTableDescriptor(const TTableDescriptor& tdesc)
275
        : TableDescriptor(tdesc),
276
          _jdbc_catalog_id(tdesc.jdbcTable.catalog_id),
277
          _jdbc_resource_name(tdesc.jdbcTable.jdbc_resource_name),
278
          _jdbc_driver_url(tdesc.jdbcTable.jdbc_driver_url),
279
          _jdbc_driver_class(tdesc.jdbcTable.jdbc_driver_class),
280
          _jdbc_driver_checksum(tdesc.jdbcTable.jdbc_driver_checksum),
281
          _jdbc_url(tdesc.jdbcTable.jdbc_url),
282
          _jdbc_table_name(tdesc.jdbcTable.jdbc_table_name),
283
          _jdbc_user(tdesc.jdbcTable.jdbc_user),
284
          _jdbc_passwd(tdesc.jdbcTable.jdbc_password),
285
          _connection_pool_min_size(tdesc.jdbcTable.connection_pool_min_size),
286
          _connection_pool_max_size(tdesc.jdbcTable.connection_pool_max_size),
287
          _connection_pool_max_wait_time(tdesc.jdbcTable.connection_pool_max_wait_time),
288
          _connection_pool_max_life_time(tdesc.jdbcTable.connection_pool_max_life_time),
289
0
          _connection_pool_keep_alive(tdesc.jdbcTable.connection_pool_keep_alive) {}
290
291
0
std::string JdbcTableDescriptor::debug_string() const {
292
0
    fmt::memory_buffer buf;
293
0
    fmt::format_to(
294
0
            buf,
295
0
            "JDBCTable({} ,_jdbc_catalog_id = {}, _jdbc_resource_name={} ,_jdbc_driver_url={} "
296
0
            ",_jdbc_driver_class={} ,_jdbc_driver_checksum={} ,_jdbc_url={} "
297
0
            ",_jdbc_table_name={} ,_jdbc_user={} ,_jdbc_passwd={} ,_connection_pool_min_size={} "
298
0
            ",_connection_pool_max_size={} ,_connection_pool_max_wait_time={} "
299
0
            ",_connection_pool_max_life_time={} ,_connection_pool_keep_alive={})",
300
0
            TableDescriptor::debug_string(), _jdbc_catalog_id, _jdbc_resource_name,
301
0
            _jdbc_driver_url, _jdbc_driver_class, _jdbc_driver_checksum, _jdbc_url,
302
0
            _jdbc_table_name, _jdbc_user, _jdbc_passwd, _connection_pool_min_size,
303
0
            _connection_pool_max_size, _connection_pool_max_wait_time,
304
0
            _connection_pool_max_life_time, _connection_pool_keep_alive);
305
0
    return fmt::to_string(buf);
306
0
}
307
308
TupleDescriptor::TupleDescriptor(const TTupleDescriptor& tdesc, bool own_slots)
309
        : _id(tdesc.id),
310
          _num_materialized_slots(0),
311
          _has_varlen_slots(false),
312
43
          _own_slots(own_slots) {}
313
314
TupleDescriptor::TupleDescriptor(const PTupleDescriptor& pdesc, bool own_slots)
315
        : _id(pdesc.id()),
316
          _num_materialized_slots(0),
317
          _has_varlen_slots(false),
318
18
          _own_slots(own_slots) {}
319
320
335
void TupleDescriptor::add_slot(SlotDescriptor* slot) {
321
335
    _slots.push_back(slot);
322
323
335
    if (slot->is_materialized()) {
324
322
        ++_num_materialized_slots;
325
326
322
        if (slot->type().is_string_type() || slot->type().is_collection_type()) {
327
86
            _has_varlen_slots = true;
328
86
        }
329
322
    }
330
335
}
331
332
16
void TupleDescriptor::to_protobuf(PTupleDescriptor* ptuple) const {
333
16
    ptuple->Clear();
334
16
    ptuple->set_id(_id);
335
    // Useless not set
336
16
    ptuple->set_byte_size(0);
337
16
    ptuple->set_table_id(-1);
338
16
    ptuple->set_num_null_bytes(0);
339
16
}
340
341
0
std::string TupleDescriptor::debug_string() const {
342
0
    std::stringstream out;
343
0
    out << "Tuple(id=" << _id;
344
0
    if (_table_desc != nullptr) {
345
        //out << " " << _table_desc->debug_string();
346
0
    }
347
348
0
    out << " slots=[";
349
0
    for (size_t i = 0; i < _slots.size(); ++i) {
350
0
        if (i > 0) {
351
0
            out << ", ";
352
0
        }
353
0
        out << _slots[i]->debug_string();
354
0
    }
355
356
0
    out << "]";
357
0
    out << " has_varlen_slots=" << _has_varlen_slots;
358
0
    out << ")";
359
0
    return out.str();
360
0
}
361
362
RowDescriptor::RowDescriptor(const DescriptorTbl& desc_tbl, const std::vector<TTupleId>& row_tuples,
363
                             const std::vector<bool>& nullable_tuples)
364
7
        : _tuple_idx_nullable_map(nullable_tuples) {
365
7
    DCHECK(nullable_tuples.size() == row_tuples.size())
366
0
            << "nullable_tuples size " << nullable_tuples.size() << " != row_tuples size "
367
0
            << row_tuples.size();
368
7
    DCHECK_GT(row_tuples.size(), 0);
369
7
    _num_materialized_slots = 0;
370
7
    _num_slots = 0;
371
372
7
    for (int row_tuple : row_tuples) {
373
7
        TupleDescriptor* tupleDesc = desc_tbl.get_tuple_descriptor(row_tuple);
374
7
        _num_materialized_slots += tupleDesc->num_materialized_slots();
375
7
        _num_slots += tupleDesc->slots().size();
376
7
        _tuple_desc_map.push_back(tupleDesc);
377
7
        DCHECK(_tuple_desc_map.back() != nullptr);
378
7
    }
379
380
7
    init_tuple_idx_map();
381
7
    init_has_varlen_slots();
382
7
}
383
384
RowDescriptor::RowDescriptor(TupleDescriptor* tuple_desc, bool is_nullable)
385
10
        : _tuple_desc_map(1, tuple_desc), _tuple_idx_nullable_map(1, is_nullable) {
386
10
    init_tuple_idx_map();
387
10
    init_has_varlen_slots();
388
10
    _num_slots = tuple_desc->slots().size();
389
10
}
390
391
0
RowDescriptor::RowDescriptor(const RowDescriptor& lhs_row_desc, const RowDescriptor& rhs_row_desc) {
392
0
    _tuple_desc_map.insert(_tuple_desc_map.end(), lhs_row_desc._tuple_desc_map.begin(),
393
0
                           lhs_row_desc._tuple_desc_map.end());
394
0
    _tuple_desc_map.insert(_tuple_desc_map.end(), rhs_row_desc._tuple_desc_map.begin(),
395
0
                           rhs_row_desc._tuple_desc_map.end());
396
0
    _tuple_idx_nullable_map.insert(_tuple_idx_nullable_map.end(),
397
0
                                   lhs_row_desc._tuple_idx_nullable_map.begin(),
398
0
                                   lhs_row_desc._tuple_idx_nullable_map.end());
399
0
    _tuple_idx_nullable_map.insert(_tuple_idx_nullable_map.end(),
400
0
                                   rhs_row_desc._tuple_idx_nullable_map.begin(),
401
0
                                   rhs_row_desc._tuple_idx_nullable_map.end());
402
0
    init_tuple_idx_map();
403
0
    init_has_varlen_slots();
404
405
0
    _num_slots = lhs_row_desc.num_slots() + rhs_row_desc.num_slots();
406
0
}
407
408
17
void RowDescriptor::init_tuple_idx_map() {
409
    // find max id
410
17
    TupleId max_id = 0;
411
17
    for (auto& i : _tuple_desc_map) {
412
17
        max_id = std::max(i->id(), max_id);
413
17
    }
414
415
17
    _tuple_idx_map.resize(max_id + 1, INVALID_IDX);
416
34
    for (int i = 0; i < _tuple_desc_map.size(); ++i) {
417
17
        _tuple_idx_map[_tuple_desc_map[i]->id()] = i;
418
17
    }
419
17
}
420
421
17
void RowDescriptor::init_has_varlen_slots() {
422
17
    _has_varlen_slots = false;
423
17
    for (auto& i : _tuple_desc_map) {
424
17
        if (i->has_varlen_slots()) {
425
8
            _has_varlen_slots = true;
426
8
            break;
427
8
        }
428
17
    }
429
17
}
430
431
0
int RowDescriptor::get_tuple_idx(TupleId id) const {
432
    // comment CHECK temporarily to make fuzzy test run smoothly
433
    // DCHECK_LT(id, _tuple_idx_map.size()) << "RowDescriptor: " << debug_string();
434
0
    if (_tuple_idx_map.size() <= id) {
435
0
        return RowDescriptor::INVALID_IDX;
436
0
    }
437
0
    return _tuple_idx_map[id];
438
0
}
439
440
0
void RowDescriptor::to_thrift(std::vector<TTupleId>* row_tuple_ids) {
441
0
    row_tuple_ids->clear();
442
443
0
    for (auto& i : _tuple_desc_map) {
444
0
        row_tuple_ids->push_back(i->id());
445
0
    }
446
0
}
447
448
void RowDescriptor::to_protobuf(
449
0
        google::protobuf::RepeatedField<google::protobuf::int32>* row_tuple_ids) const {
450
0
    row_tuple_ids->Clear();
451
0
    for (auto* desc : _tuple_desc_map) {
452
0
        row_tuple_ids->Add(desc->id());
453
0
    }
454
0
}
455
456
0
bool RowDescriptor::is_prefix_of(const RowDescriptor& other_desc) const {
457
0
    if (_tuple_desc_map.size() > other_desc._tuple_desc_map.size()) {
458
0
        return false;
459
0
    }
460
461
0
    for (int i = 0; i < _tuple_desc_map.size(); ++i) {
462
        // pointer comparison okay, descriptors are unique
463
0
        if (_tuple_desc_map[i] != other_desc._tuple_desc_map[i]) {
464
0
            return false;
465
0
        }
466
0
    }
467
468
0
    return true;
469
0
}
470
471
0
bool RowDescriptor::equals(const RowDescriptor& other_desc) const {
472
0
    if (_tuple_desc_map.size() != other_desc._tuple_desc_map.size()) {
473
0
        return false;
474
0
    }
475
476
0
    for (int i = 0; i < _tuple_desc_map.size(); ++i) {
477
        // pointer comparison okay, descriptors are unique
478
0
        if (_tuple_desc_map[i] != other_desc._tuple_desc_map[i]) {
479
0
            return false;
480
0
        }
481
0
    }
482
483
0
    return true;
484
0
}
485
486
0
std::string RowDescriptor::debug_string() const {
487
0
    std::stringstream ss;
488
489
0
    ss << "tuple_desc_map: [";
490
0
    for (int i = 0; i < _tuple_desc_map.size(); ++i) {
491
0
        ss << _tuple_desc_map[i]->debug_string();
492
0
        if (i != _tuple_desc_map.size() - 1) {
493
0
            ss << ", ";
494
0
        }
495
0
    }
496
0
    ss << "] ";
497
498
0
    ss << "tuple_id_map: [";
499
0
    for (int i = 0; i < _tuple_idx_map.size(); ++i) {
500
0
        ss << _tuple_idx_map[i];
501
0
        if (i != _tuple_idx_map.size() - 1) {
502
0
            ss << ", ";
503
0
        }
504
0
    }
505
0
    ss << "] ";
506
507
0
    ss << "tuple_is_nullable: [";
508
0
    for (int i = 0; i < _tuple_idx_nullable_map.size(); ++i) {
509
0
        ss << _tuple_idx_nullable_map[i];
510
0
        if (i != _tuple_idx_nullable_map.size() - 1) {
511
0
            ss << ", ";
512
0
        }
513
0
    }
514
0
    ss << "] ";
515
516
0
    return ss.str();
517
0
}
518
519
10
int RowDescriptor::get_column_id(int slot_id, bool force_materialize_slot) const {
520
10
    int column_id_counter = 0;
521
10
    for (auto* const tuple_desc : _tuple_desc_map) {
522
10
        for (auto* const slot : tuple_desc->slots()) {
523
10
            if (!force_materialize_slot && !slot->need_materialize()) {
524
0
                continue;
525
0
            }
526
10
            if (slot->id() == slot_id) {
527
10
                return column_id_counter;
528
10
            }
529
0
            column_id_counter++;
530
0
        }
531
10
    }
532
0
    return -1;
533
10
}
534
535
Status DescriptorTbl::create(ObjectPool* pool, const TDescriptorTable& thrift_tbl,
536
24
                             DescriptorTbl** tbl) {
537
24
    *tbl = pool->add(new DescriptorTbl());
538
539
    // deserialize table descriptors first, they are being referenced by tuple descriptors
540
24
    for (const auto& tdesc : thrift_tbl.tableDescriptors) {
541
4
        TableDescriptor* desc = nullptr;
542
543
4
        switch (tdesc.tableType) {
544
0
        case TTableType::MYSQL_TABLE:
545
0
            desc = pool->add(new MySQLTableDescriptor(tdesc));
546
0
            break;
547
548
0
        case TTableType::ODBC_TABLE:
549
0
            desc = pool->add(new ODBCTableDescriptor(tdesc));
550
0
            break;
551
552
4
        case TTableType::OLAP_TABLE:
553
4
            desc = pool->add(new OlapTableDescriptor(tdesc));
554
4
            break;
555
556
0
        case TTableType::SCHEMA_TABLE:
557
0
            desc = pool->add(new SchemaTableDescriptor(tdesc));
558
0
            break;
559
0
        case TTableType::BROKER_TABLE:
560
0
            desc = pool->add(new BrokerTableDescriptor(tdesc));
561
0
            break;
562
0
        case TTableType::ES_TABLE:
563
0
            desc = pool->add(new EsTableDescriptor(tdesc));
564
0
            break;
565
0
        case TTableType::HIVE_TABLE:
566
0
            desc = pool->add(new HiveTableDescriptor(tdesc));
567
0
            break;
568
0
        case TTableType::ICEBERG_TABLE:
569
0
            desc = pool->add(new IcebergTableDescriptor(tdesc));
570
0
            break;
571
0
        case TTableType::JDBC_TABLE:
572
0
            desc = pool->add(new JdbcTableDescriptor(tdesc));
573
0
            break;
574
0
        case TTableType::MAX_COMPUTE_TABLE:
575
0
            desc = pool->add(new MaxComputeTableDescriptor(tdesc));
576
0
            break;
577
0
        case TTableType::TRINO_CONNECTOR_TABLE:
578
0
            desc = pool->add(new TrinoConnectorTableDescriptor(tdesc));
579
0
            break;
580
0
        default:
581
0
            DCHECK(false) << "invalid table type: " << tdesc.tableType;
582
4
        }
583
584
4
        (*tbl)->_tbl_desc_map[tdesc.id] = desc;
585
4
    }
586
587
24
    for (const auto& tdesc : thrift_tbl.tupleDescriptors) {
588
24
        TupleDescriptor* desc = pool->add(new TupleDescriptor(tdesc));
589
590
        // fix up table pointer
591
24
        if (tdesc.__isset.tableId) {
592
4
            desc->_table_desc = (*tbl)->get_table_descriptor(tdesc.tableId);
593
4
            DCHECK(desc->_table_desc != nullptr);
594
4
        }
595
596
24
        (*tbl)->_tuple_desc_map[tdesc.id] = desc;
597
24
        (*tbl)->_row_tuples.emplace_back(tdesc.id);
598
24
    }
599
600
109
    for (const auto& tdesc : thrift_tbl.slotDescriptors) {
601
109
        SlotDescriptor* slot_d = pool->add(new SlotDescriptor(tdesc));
602
109
        (*tbl)->_slot_desc_map[tdesc.id] = slot_d;
603
604
        // link to parent
605
109
        auto entry = (*tbl)->_tuple_desc_map.find(tdesc.parent);
606
607
109
        if (entry == (*tbl)->_tuple_desc_map.end()) {
608
0
            return Status::InternalError("unknown tid in slot descriptor msg");
609
0
        }
610
109
        entry->second->add_slot(slot_d);
611
109
    }
612
613
24
    return Status::OK();
614
24
}
615
616
4
TableDescriptor* DescriptorTbl::get_table_descriptor(TableId id) const {
617
    // TODO: is there some boost function to do exactly this?
618
4
    auto i = _tbl_desc_map.find(id);
619
620
4
    if (i == _tbl_desc_map.end()) {
621
0
        return nullptr;
622
4
    } else {
623
4
        return i->second;
624
4
    }
625
4
}
626
627
42
TupleDescriptor* DescriptorTbl::get_tuple_descriptor(TupleId id) const {
628
    // TODO: is there some boost function to do exactly this?
629
42
    auto i = _tuple_desc_map.find(id);
630
631
42
    if (i == _tuple_desc_map.end()) {
632
3
        return nullptr;
633
39
    } else {
634
39
        return i->second;
635
39
    }
636
42
}
637
638
10
SlotDescriptor* DescriptorTbl::get_slot_descriptor(SlotId id) const {
639
    // TODO: is there some boost function to do exactly this?
640
10
    auto i = _slot_desc_map.find(id);
641
642
10
    if (i == _slot_desc_map.end()) {
643
0
        return nullptr;
644
10
    } else {
645
10
        return i->second;
646
10
    }
647
10
}
648
649
0
std::string DescriptorTbl::debug_string() const {
650
0
    std::stringstream out;
651
0
    out << "tuples:\n";
652
653
0
    for (auto i : _tuple_desc_map) {
654
0
        out << i.second->debug_string() << '\n';
655
0
    }
656
657
0
    return out.str();
658
0
}
659
660
} // namespace doris