Coverage Report

Created: 2025-11-20 23:54

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