Coverage Report

Created: 2024-11-20 12:30

/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
310
          _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
122
void SlotDescriptor::to_protobuf(PSlotDescriptor* pslot) const {
81
122
    pslot->set_id(_id);
82
122
    pslot->set_parent(_parent);
83
122
    _type.to_protobuf(pslot->mutable_slot_type());
84
122
    pslot->set_column_pos(_col_pos);
85
122
    pslot->set_byte_offset(0);
86
122
    pslot->set_null_indicator_byte(0);
87
122
    pslot->set_null_indicator_bit(_is_nullable ? 0 : -1);
88
122
    pslot->set_col_name(_col_name);
89
122
    pslot->set_slot_idx(_slot_idx);
90
122
    pslot->set_is_materialized(_is_materialized);
91
122
    pslot->set_col_unique_id(_col_unique_id);
92
122
    pslot->set_is_key(_is_key);
93
122
    pslot->set_is_auto_increment(_is_auto_increment);
94
122
    pslot->set_col_type(_col_type);
95
122
    for (const std::string& path : _column_paths) {
96
0
        pslot->add_column_paths(path);
97
0
    }
98
122
}
99
100
109
vectorized::MutableColumnPtr SlotDescriptor::get_empty_mutable_column() const {
101
109
    auto data_type = get_data_type_ptr();
102
109
    if (data_type) {
103
109
        return data_type->create_column();
104
109
    }
105
0
    return nullptr;
106
109
}
107
108
254
vectorized::DataTypePtr SlotDescriptor::get_data_type_ptr() const {
109
254
    return vectorized::DataTypeFactory::instance().create_data_type(type(), is_nullable());
110
254
}
111
112
8
std::string SlotDescriptor::debug_string() const {
113
8
    std::stringstream out;
114
8
    out << "Slot(id=" << _id << " type=" << _type << " col=" << _col_pos
115
8
        << ", colname=" << _col_name << ", nullable=" << is_nullable() << ")";
116
8
    return out.str();
117
8
}
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
3
          _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
3
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
0
EsTableDescriptor::EsTableDescriptor(const TTableDescriptor& tdesc) : TableDescriptor(tdesc) {}
217
218
0
EsTableDescriptor::~EsTableDescriptor() = default;
219
220
0
std::string EsTableDescriptor::debug_string() const {
221
0
    std::stringstream out;
222
0
    out << "EsTable(" << TableDescriptor::debug_string() << ")";
223
0
    return out.str();
224
0
}
225
226
MySQLTableDescriptor::MySQLTableDescriptor(const TTableDescriptor& tdesc)
227
        : TableDescriptor(tdesc),
228
          _mysql_db(tdesc.mysqlTable.db),
229
          _mysql_table(tdesc.mysqlTable.table),
230
          _host(tdesc.mysqlTable.host),
231
          _port(tdesc.mysqlTable.port),
232
          _user(tdesc.mysqlTable.user),
233
          _passwd(tdesc.mysqlTable.passwd),
234
0
          _charset(tdesc.mysqlTable.charset) {}
235
236
0
std::string MySQLTableDescriptor::debug_string() const {
237
0
    std::stringstream out;
238
0
    out << "MySQLTable(" << TableDescriptor::debug_string() << " _db" << _mysql_db
239
0
        << " table=" << _mysql_table << " host=" << _host << " port=" << _port << " user=" << _user
240
0
        << " passwd=" << _passwd << " charset=" << _charset;
241
0
    return out.str();
242
0
}
243
244
ODBCTableDescriptor::ODBCTableDescriptor(const TTableDescriptor& tdesc)
245
        : TableDescriptor(tdesc),
246
          _db(tdesc.odbcTable.db),
247
          _table(tdesc.odbcTable.table),
248
          _host(tdesc.odbcTable.host),
249
          _port(tdesc.odbcTable.port),
250
          _user(tdesc.odbcTable.user),
251
          _passwd(tdesc.odbcTable.passwd),
252
          _driver(tdesc.odbcTable.driver),
253
0
          _type(tdesc.odbcTable.type) {}
254
255
0
std::string ODBCTableDescriptor::debug_string() const {
256
0
    std::stringstream out;
257
0
    out << "ODBCTable(" << TableDescriptor::debug_string() << " _db" << _db << " table=" << _table
258
0
        << " host=" << _host << " port=" << _port << " user=" << _user << " passwd=" << _passwd
259
0
        << " driver=" << _driver << " type" << _type;
260
0
    return out.str();
261
0
}
262
263
JdbcTableDescriptor::JdbcTableDescriptor(const TTableDescriptor& tdesc)
264
        : TableDescriptor(tdesc),
265
          _jdbc_catalog_id(tdesc.jdbcTable.catalog_id),
266
          _jdbc_resource_name(tdesc.jdbcTable.jdbc_resource_name),
267
          _jdbc_driver_url(tdesc.jdbcTable.jdbc_driver_url),
268
          _jdbc_driver_class(tdesc.jdbcTable.jdbc_driver_class),
269
          _jdbc_driver_checksum(tdesc.jdbcTable.jdbc_driver_checksum),
270
          _jdbc_url(tdesc.jdbcTable.jdbc_url),
271
          _jdbc_table_name(tdesc.jdbcTable.jdbc_table_name),
272
          _jdbc_user(tdesc.jdbcTable.jdbc_user),
273
          _jdbc_passwd(tdesc.jdbcTable.jdbc_password),
274
          _connection_pool_min_size(tdesc.jdbcTable.connection_pool_min_size),
275
          _connection_pool_max_size(tdesc.jdbcTable.connection_pool_max_size),
276
          _connection_pool_max_wait_time(tdesc.jdbcTable.connection_pool_max_wait_time),
277
          _connection_pool_max_life_time(tdesc.jdbcTable.connection_pool_max_life_time),
278
0
          _connection_pool_keep_alive(tdesc.jdbcTable.connection_pool_keep_alive) {}
279
280
0
std::string JdbcTableDescriptor::debug_string() const {
281
0
    fmt::memory_buffer buf;
282
0
    fmt::format_to(
283
0
            buf,
284
0
            "JDBCTable({} ,_jdbc_catalog_id = {}, _jdbc_resource_name={} ,_jdbc_driver_url={} "
285
0
            ",_jdbc_driver_class={} ,_jdbc_driver_checksum={} ,_jdbc_url={} "
286
0
            ",_jdbc_table_name={} ,_jdbc_user={} ,_jdbc_passwd={} ,_connection_pool_min_size={} "
287
0
            ",_connection_pool_max_size={} ,_connection_pool_max_wait_time={} "
288
0
            ",_connection_pool_max_life_time={} ,_connection_pool_keep_alive={})",
289
0
            TableDescriptor::debug_string(), _jdbc_catalog_id, _jdbc_resource_name,
290
0
            _jdbc_driver_url, _jdbc_driver_class, _jdbc_driver_checksum, _jdbc_url,
291
0
            _jdbc_table_name, _jdbc_user, _jdbc_passwd, _connection_pool_min_size,
292
0
            _connection_pool_max_size, _connection_pool_max_wait_time,
293
0
            _connection_pool_max_life_time, _connection_pool_keep_alive);
294
0
    return fmt::to_string(buf);
295
0
}
296
297
TupleDescriptor::TupleDescriptor(const TTupleDescriptor& tdesc, bool own_slots)
298
        : _id(tdesc.id),
299
          _num_materialized_slots(0),
300
          _has_varlen_slots(false),
301
55
          _own_slots(own_slots) {}
302
303
TupleDescriptor::TupleDescriptor(const PTupleDescriptor& pdesc, bool own_slots)
304
        : _id(pdesc.id()),
305
          _num_materialized_slots(0),
306
          _has_varlen_slots(false),
307
21
          _own_slots(own_slots) {}
308
309
394
void TupleDescriptor::add_slot(SlotDescriptor* slot) {
310
394
    _slots.push_back(slot);
311
312
394
    if (slot->is_materialized()) {
313
366
        ++_num_materialized_slots;
314
315
366
        if (slot->type().is_string_type() || slot->type().is_collection_type()) {
316
99
            _has_varlen_slots = true;
317
99
        }
318
366
    }
319
394
}
320
321
21
void TupleDescriptor::to_protobuf(PTupleDescriptor* ptuple) const {
322
21
    ptuple->Clear();
323
21
    ptuple->set_id(_id);
324
    // Useless not set
325
21
    ptuple->set_byte_size(0);
326
21
    ptuple->set_table_id(-1);
327
21
    ptuple->set_num_null_bytes(0);
328
21
}
329
330
3
std::string TupleDescriptor::debug_string() const {
331
3
    std::stringstream out;
332
3
    out << "Tuple(id=" << _id;
333
3
    if (_table_desc != nullptr) {
334
        //out << " " << _table_desc->debug_string();
335
0
    }
336
337
3
    out << " slots=[";
338
11
    for (size_t i = 0; i < _slots.size(); ++i) {
339
8
        if (i > 0) {
340
5
            out << ", ";
341
5
        }
342
8
        out << _slots[i]->debug_string();
343
8
    }
344
345
3
    out << "]";
346
3
    out << " has_varlen_slots=" << _has_varlen_slots;
347
3
    out << ")";
348
3
    return out.str();
349
3
}
350
351
RowDescriptor::RowDescriptor(const DescriptorTbl& desc_tbl, const std::vector<TTupleId>& row_tuples,
352
                             const std::vector<bool>& nullable_tuples)
353
10
        : _tuple_idx_nullable_map(nullable_tuples) {
354
10
    DCHECK(nullable_tuples.size() == row_tuples.size())
355
0
            << "nullable_tuples size " << nullable_tuples.size() << " != row_tuples size "
356
0
            << row_tuples.size();
357
10
    DCHECK_GT(row_tuples.size(), 0);
358
10
    _num_materialized_slots = 0;
359
10
    _num_slots = 0;
360
361
10
    for (int row_tuple : row_tuples) {
362
10
        TupleDescriptor* tupleDesc = desc_tbl.get_tuple_descriptor(row_tuple);
363
10
        _num_materialized_slots += tupleDesc->num_materialized_slots();
364
10
        _num_slots += tupleDesc->slots().size();
365
10
        _tuple_desc_map.push_back(tupleDesc);
366
10
        DCHECK(_tuple_desc_map.back() != nullptr);
367
10
    }
368
369
10
    init_tuple_idx_map();
370
10
    init_has_varlen_slots();
371
10
}
372
373
RowDescriptor::RowDescriptor(TupleDescriptor* tuple_desc, bool is_nullable)
374
33
        : _tuple_desc_map(1, tuple_desc), _tuple_idx_nullable_map(1, is_nullable) {
375
33
    init_tuple_idx_map();
376
33
    init_has_varlen_slots();
377
33
    _num_slots = tuple_desc->slots().size();
378
33
}
379
380
0
RowDescriptor::RowDescriptor(const RowDescriptor& lhs_row_desc, const RowDescriptor& rhs_row_desc) {
381
0
    _tuple_desc_map.insert(_tuple_desc_map.end(), lhs_row_desc._tuple_desc_map.begin(),
382
0
                           lhs_row_desc._tuple_desc_map.end());
383
0
    _tuple_desc_map.insert(_tuple_desc_map.end(), rhs_row_desc._tuple_desc_map.begin(),
384
0
                           rhs_row_desc._tuple_desc_map.end());
385
0
    _tuple_idx_nullable_map.insert(_tuple_idx_nullable_map.end(),
386
0
                                   lhs_row_desc._tuple_idx_nullable_map.begin(),
387
0
                                   lhs_row_desc._tuple_idx_nullable_map.end());
388
0
    _tuple_idx_nullable_map.insert(_tuple_idx_nullable_map.end(),
389
0
                                   rhs_row_desc._tuple_idx_nullable_map.begin(),
390
0
                                   rhs_row_desc._tuple_idx_nullable_map.end());
391
0
    init_tuple_idx_map();
392
0
    init_has_varlen_slots();
393
394
0
    _num_slots = lhs_row_desc.num_slots() + rhs_row_desc.num_slots();
395
0
}
396
397
43
void RowDescriptor::init_tuple_idx_map() {
398
    // find max id
399
43
    TupleId max_id = 0;
400
43
    for (auto& i : _tuple_desc_map) {
401
43
        max_id = std::max(i->id(), max_id);
402
43
    }
403
404
43
    _tuple_idx_map.resize(max_id + 1, INVALID_IDX);
405
86
    for (int i = 0; i < _tuple_desc_map.size(); ++i) {
406
43
        _tuple_idx_map[_tuple_desc_map[i]->id()] = i;
407
43
    }
408
43
}
409
410
43
void RowDescriptor::init_has_varlen_slots() {
411
43
    _has_varlen_slots = false;
412
43
    for (auto& i : _tuple_desc_map) {
413
43
        if (i->has_varlen_slots()) {
414
26
            _has_varlen_slots = true;
415
26
            break;
416
26
        }
417
43
    }
418
43
}
419
420
0
int RowDescriptor::get_tuple_idx(TupleId id) const {
421
    // comment CHECK temporarily to make fuzzy test run smoothly
422
    // DCHECK_LT(id, _tuple_idx_map.size()) << "RowDescriptor: " << debug_string();
423
0
    if (_tuple_idx_map.size() <= id) {
424
0
        return RowDescriptor::INVALID_IDX;
425
0
    }
426
0
    return _tuple_idx_map[id];
427
0
}
428
429
0
void RowDescriptor::to_thrift(std::vector<TTupleId>* row_tuple_ids) {
430
0
    row_tuple_ids->clear();
431
432
0
    for (auto& i : _tuple_desc_map) {
433
0
        row_tuple_ids->push_back(i->id());
434
0
    }
435
0
}
436
437
void RowDescriptor::to_protobuf(
438
0
        google::protobuf::RepeatedField<google::protobuf::int32>* row_tuple_ids) const {
439
0
    row_tuple_ids->Clear();
440
0
    for (auto* desc : _tuple_desc_map) {
441
0
        row_tuple_ids->Add(desc->id());
442
0
    }
443
0
}
444
445
0
bool RowDescriptor::is_prefix_of(const RowDescriptor& other_desc) const {
446
0
    if (_tuple_desc_map.size() > other_desc._tuple_desc_map.size()) {
447
0
        return false;
448
0
    }
449
450
0
    for (int i = 0; i < _tuple_desc_map.size(); ++i) {
451
        // pointer comparison okay, descriptors are unique
452
0
        if (_tuple_desc_map[i] != other_desc._tuple_desc_map[i]) {
453
0
            return false;
454
0
        }
455
0
    }
456
457
0
    return true;
458
0
}
459
460
0
bool RowDescriptor::equals(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
std::string RowDescriptor::debug_string() const {
476
0
    std::stringstream ss;
477
478
0
    ss << "tuple_desc_map: [";
479
0
    for (int i = 0; i < _tuple_desc_map.size(); ++i) {
480
0
        ss << _tuple_desc_map[i]->debug_string();
481
0
        if (i != _tuple_desc_map.size() - 1) {
482
0
            ss << ", ";
483
0
        }
484
0
    }
485
0
    ss << "] ";
486
487
0
    ss << "tuple_id_map: [";
488
0
    for (int i = 0; i < _tuple_idx_map.size(); ++i) {
489
0
        ss << _tuple_idx_map[i];
490
0
        if (i != _tuple_idx_map.size() - 1) {
491
0
            ss << ", ";
492
0
        }
493
0
    }
494
0
    ss << "] ";
495
496
0
    ss << "tuple_is_nullable: [";
497
0
    for (int i = 0; i < _tuple_idx_nullable_map.size(); ++i) {
498
0
        ss << _tuple_idx_nullable_map[i];
499
0
        if (i != _tuple_idx_nullable_map.size() - 1) {
500
0
            ss << ", ";
501
0
        }
502
0
    }
503
0
    ss << "] ";
504
505
0
    return ss.str();
506
0
}
507
508
16
int RowDescriptor::get_column_id(int slot_id, bool force_materialize_slot) const {
509
16
    int column_id_counter = 0;
510
16
    for (auto* const tuple_desc : _tuple_desc_map) {
511
22
        for (auto* const slot : tuple_desc->slots()) {
512
22
            if (!force_materialize_slot && !slot->need_materialize()) {
513
0
                continue;
514
0
            }
515
22
            if (slot->id() == slot_id) {
516
16
                return column_id_counter;
517
16
            }
518
6
            column_id_counter++;
519
6
        }
520
16
    }
521
0
    return -1;
522
16
}
523
524
Status DescriptorTbl::create(ObjectPool* pool, const TDescriptorTable& thrift_tbl,
525
27
                             DescriptorTbl** tbl) {
526
27
    *tbl = pool->add(new DescriptorTbl());
527
528
    // deserialize table descriptors first, they are being referenced by tuple descriptors
529
27
    for (const auto& tdesc : thrift_tbl.tableDescriptors) {
530
3
        TableDescriptor* desc = nullptr;
531
532
3
        switch (tdesc.tableType) {
533
0
        case TTableType::MYSQL_TABLE:
534
0
            desc = pool->add(new MySQLTableDescriptor(tdesc));
535
0
            break;
536
537
0
        case TTableType::ODBC_TABLE:
538
0
            desc = pool->add(new ODBCTableDescriptor(tdesc));
539
0
            break;
540
541
3
        case TTableType::OLAP_TABLE:
542
3
            desc = pool->add(new OlapTableDescriptor(tdesc));
543
3
            break;
544
545
0
        case TTableType::SCHEMA_TABLE:
546
0
            desc = pool->add(new SchemaTableDescriptor(tdesc));
547
0
            break;
548
0
        case TTableType::BROKER_TABLE:
549
0
            desc = pool->add(new BrokerTableDescriptor(tdesc));
550
0
            break;
551
0
        case TTableType::ES_TABLE:
552
0
            desc = pool->add(new EsTableDescriptor(tdesc));
553
0
            break;
554
0
        case TTableType::HIVE_TABLE:
555
0
            desc = pool->add(new HiveTableDescriptor(tdesc));
556
0
            break;
557
0
        case TTableType::ICEBERG_TABLE:
558
0
            desc = pool->add(new IcebergTableDescriptor(tdesc));
559
0
            break;
560
0
        case TTableType::JDBC_TABLE:
561
0
            desc = pool->add(new JdbcTableDescriptor(tdesc));
562
0
            break;
563
0
        case TTableType::MAX_COMPUTE_TABLE:
564
0
            desc = pool->add(new MaxComputeTableDescriptor(tdesc));
565
0
            break;
566
0
        default:
567
0
            DCHECK(false) << "invalid table type: " << tdesc.tableType;
568
3
        }
569
570
3
        (*tbl)->_tbl_desc_map[tdesc.id] = desc;
571
3
    }
572
573
31
    for (const auto& tdesc : thrift_tbl.tupleDescriptors) {
574
31
        TupleDescriptor* desc = pool->add(new TupleDescriptor(tdesc));
575
576
        // fix up table pointer
577
31
        if (tdesc.__isset.tableId) {
578
3
            desc->_table_desc = (*tbl)->get_table_descriptor(tdesc.tableId);
579
3
            DCHECK(desc->_table_desc != nullptr);
580
3
        }
581
582
31
        (*tbl)->_tuple_desc_map[tdesc.id] = desc;
583
31
        (*tbl)->_row_tuples.emplace_back(tdesc.id);
584
31
    }
585
586
127
    for (const auto& tdesc : thrift_tbl.slotDescriptors) {
587
127
        SlotDescriptor* slot_d = pool->add(new SlotDescriptor(tdesc));
588
127
        (*tbl)->_slot_desc_map[tdesc.id] = slot_d;
589
590
        // link to parent
591
127
        auto entry = (*tbl)->_tuple_desc_map.find(tdesc.parent);
592
593
127
        if (entry == (*tbl)->_tuple_desc_map.end()) {
594
0
            return Status::InternalError("unknown tid in slot descriptor msg");
595
0
        }
596
127
        entry->second->add_slot(slot_d);
597
127
    }
598
599
27
    return Status::OK();
600
27
}
601
602
3
TableDescriptor* DescriptorTbl::get_table_descriptor(TableId id) const {
603
    // TODO: is there some boost function to do exactly this?
604
3
    auto i = _tbl_desc_map.find(id);
605
606
3
    if (i == _tbl_desc_map.end()) {
607
0
        return nullptr;
608
3
    } else {
609
3
        return i->second;
610
3
    }
611
3
}
612
613
46
TupleDescriptor* DescriptorTbl::get_tuple_descriptor(TupleId id) const {
614
    // TODO: is there some boost function to do exactly this?
615
46
    auto i = _tuple_desc_map.find(id);
616
617
46
    if (i == _tuple_desc_map.end()) {
618
0
        return nullptr;
619
46
    } else {
620
46
        return i->second;
621
46
    }
622
46
}
623
624
16
SlotDescriptor* DescriptorTbl::get_slot_descriptor(SlotId id) const {
625
    // TODO: is there some boost function to do exactly this?
626
16
    auto i = _slot_desc_map.find(id);
627
628
16
    if (i == _slot_desc_map.end()) {
629
0
        return nullptr;
630
16
    } else {
631
16
        return i->second;
632
16
    }
633
16
}
634
635
0
std::string DescriptorTbl::debug_string() const {
636
0
    std::stringstream out;
637
0
    out << "tuples:\n";
638
639
0
    for (auto i : _tuple_desc_map) {
640
0
        out << i.second->debug_string() << '\n';
641
0
    }
642
643
0
    return out.str();
644
0
}
645
646
} // namespace doris