Coverage Report

Created: 2025-06-03 16:15

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