Coverage Report

Created: 2025-05-13 21:53

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