be/src/runtime/descriptors.h
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.h |
19 | | // and modified by Doris |
20 | | |
21 | | #pragma once |
22 | | |
23 | | #include <gen_cpp/Descriptors_types.h> |
24 | | #include <gen_cpp/Exprs_types.h> |
25 | | #include <gen_cpp/Types_types.h> |
26 | | #include <glog/logging.h> |
27 | | |
28 | | #include <cstdint> |
29 | | #include <ostream> |
30 | | #include <string> |
31 | | #include <unordered_map> |
32 | | #include <utility> |
33 | | #include <vector> |
34 | | |
35 | | #include "common/be_mock_util.h" |
36 | | #include "common/compiler_util.h" // IWYU pragma: keep |
37 | | #include "common/global_types.h" |
38 | | #include "common/object_pool.h" |
39 | | #include "common/status.h" |
40 | | #include "core/data_type/data_type.h" |
41 | | #include "core/data_type/define_primitive_type.h" |
42 | | #include "storage/utils.h" |
43 | | |
44 | | namespace doris { |
45 | | class ObjectPool; |
46 | | class PTupleDescriptor; |
47 | | class PSlotDescriptor; |
48 | | |
49 | | using TColumnAccessPaths = std::vector<TColumnAccessPath>; |
50 | | |
51 | | class SlotDescriptor { |
52 | | public: |
53 | | MOCK_DEFINE(virtual ~SlotDescriptor() = default;) |
54 | 658k | SlotId id() const { return _id; } |
55 | 3.33M | DataTypePtr type() const { return _type; } |
56 | 0 | TupleId parent() const { return _parent; } |
57 | | // Returns the column index of this slot, including partition keys. |
58 | | // (e.g., col_pos - num_partition_keys = the table column this slot corresponds to) |
59 | 26 | int col_pos() const { return _col_pos; } |
60 | | // Returns the field index in the generated llvm struct for this slot's tuple |
61 | 0 | int field_idx() const { return _field_idx; } |
62 | | bool is_nullable() const; |
63 | | DataTypePtr get_data_type_ptr() const; |
64 | | |
65 | 911k | const std::string& col_name() const { return _col_name; } |
66 | 182 | const std::string& col_name_lower_case() const { return _col_name_lower_case; } |
67 | | |
68 | | void to_protobuf(PSlotDescriptor* pslot) const; |
69 | | |
70 | | std::string debug_string() const; |
71 | | |
72 | | MutableColumnPtr get_empty_mutable_column() const; |
73 | | |
74 | 351k | MOCK_FUNCTION int32_t col_unique_id() const { return _col_unique_id; } |
75 | | |
76 | 1 | bool is_key() const { return _is_key; } |
77 | 61 | const std::vector<std::string>& column_paths() const { return _column_paths; }; |
78 | | |
79 | 89.0k | const TColumnAccessPaths& all_access_paths() const { return _all_access_paths; } |
80 | 88.9k | const TColumnAccessPaths& predicate_access_paths() const { return _predicate_access_paths; } |
81 | | |
82 | 4 | bool is_auto_increment() const { return _is_auto_increment; } |
83 | | |
84 | 1.30k | bool is_skip_bitmap_col() const { return _col_name == SKIP_BITMAP_COL; } |
85 | 0 | bool is_sequence_col() const { return _col_name == SEQUENCE_COL; } |
86 | | |
87 | 89.0k | const std::string& col_default_value() const { return _col_default_value; } |
88 | | PrimitiveType col_type() const; |
89 | | |
90 | 272k | std::shared_ptr<doris::TExpr> get_virtual_column_expr() const { |
91 | | // virtual_column_expr need do prepare. |
92 | 272k | return virtual_column_expr; |
93 | 272k | } |
94 | | |
95 | 0 | void set_is_predicate(bool is_predicate) { _is_predicate = is_predicate; } |
96 | | |
97 | 217 | bool is_predicate() const { return _is_predicate; } |
98 | | |
99 | | private: |
100 | | friend class DescriptorTbl; |
101 | | friend class TupleDescriptor; |
102 | | friend class SchemaScanner; |
103 | | friend class OlapTableSchemaParam; |
104 | | friend class PInternalServiceImpl; |
105 | | friend class RowIdStorageReader; |
106 | | friend class Tablet; |
107 | | friend class TabletSchema; |
108 | | |
109 | | MOCK_REMOVE(const) SlotId _id; |
110 | | MOCK_REMOVE(const) DataTypePtr _type; |
111 | | const TupleId _parent; |
112 | | const int _col_pos; |
113 | | MOCK_REMOVE(const) std::string _col_name; |
114 | | const std::string _col_name_lower_case; |
115 | | |
116 | | const int32_t _col_unique_id; |
117 | | |
118 | | // the idx of the slot in the tuple descriptor (0-based). |
119 | | // this is provided by the FE |
120 | | const int _slot_idx; |
121 | | |
122 | | // the idx of the slot in the llvm codegen'd tuple struct |
123 | | // this is set by TupleDescriptor during codegen and takes into account |
124 | | // leading null bytes. |
125 | | int _field_idx; |
126 | | |
127 | | const bool _is_key; |
128 | | const std::vector<std::string> _column_paths; |
129 | | |
130 | | TColumnAccessPaths _all_access_paths; |
131 | | TColumnAccessPaths _predicate_access_paths; |
132 | | |
133 | | const bool _is_auto_increment; |
134 | | const std::string _col_default_value; |
135 | | |
136 | | std::shared_ptr<doris::TExpr> virtual_column_expr = nullptr; |
137 | | |
138 | | bool _is_predicate = false; |
139 | | |
140 | | SlotDescriptor(const TSlotDescriptor& tdesc); |
141 | | SlotDescriptor(const PSlotDescriptor& pdesc); |
142 | | MOCK_DEFINE(SlotDescriptor();) |
143 | | }; |
144 | | |
145 | | // Base class for table descriptors. |
146 | | class TableDescriptor { |
147 | | public: |
148 | | TableDescriptor(const TTableDescriptor& tdesc); |
149 | 289 | virtual ~TableDescriptor() = default; |
150 | 0 | int num_cols() const { return _num_cols; } |
151 | 0 | int num_clustering_cols() const { return _num_clustering_cols; } |
152 | | virtual std::string debug_string() const; |
153 | | |
154 | | // The first _num_clustering_cols columns by position are clustering |
155 | | // columns. |
156 | 0 | bool is_clustering_col(const SlotDescriptor* slot_desc) const { |
157 | 0 | return slot_desc->col_pos() < _num_clustering_cols; |
158 | 0 | } |
159 | | |
160 | 0 | ::doris::TTableType::type table_type() const { return _table_type; } |
161 | 0 | const std::string& name() const { return _name; } |
162 | 0 | const std::string& database() const { return _database; } |
163 | 0 | int64_t table_id() const { return _table_id; } |
164 | | |
165 | | private: |
166 | | ::doris::TTableType::type _table_type; |
167 | | std::string _name; |
168 | | std::string _database; |
169 | | int64_t _table_id; |
170 | | int _num_cols; |
171 | | int _num_clustering_cols; |
172 | | }; |
173 | | |
174 | | class OlapTableDescriptor : public TableDescriptor { |
175 | | public: |
176 | | OlapTableDescriptor(const TTableDescriptor& tdesc); |
177 | | std::string debug_string() const override; |
178 | | }; |
179 | | |
180 | | class DictionaryTableDescriptor : public TableDescriptor { |
181 | | public: |
182 | | DictionaryTableDescriptor(const TTableDescriptor& tdesc); |
183 | | std::string debug_string() const override; |
184 | | }; |
185 | | |
186 | | class SchemaTableDescriptor : public TableDescriptor { |
187 | | public: |
188 | | SchemaTableDescriptor(const TTableDescriptor& tdesc); |
189 | | ~SchemaTableDescriptor() override; |
190 | | std::string debug_string() const override; |
191 | 0 | TSchemaTableType::type schema_table_type() const { return _schema_table_type; } |
192 | | |
193 | | private: |
194 | | TSchemaTableType::type _schema_table_type; |
195 | | }; |
196 | | |
197 | | class BrokerTableDescriptor : public TableDescriptor { |
198 | | public: |
199 | | BrokerTableDescriptor(const TTableDescriptor& tdesc); |
200 | | ~BrokerTableDescriptor() override; |
201 | | std::string debug_string() const override; |
202 | | |
203 | | private: |
204 | | }; |
205 | | |
206 | | class HiveTableDescriptor : public TableDescriptor { |
207 | | public: |
208 | | HiveTableDescriptor(const TTableDescriptor& tdesc); |
209 | | ~HiveTableDescriptor() override; |
210 | | std::string debug_string() const override; |
211 | | |
212 | | private: |
213 | | }; |
214 | | |
215 | | class IcebergTableDescriptor : public TableDescriptor { |
216 | | public: |
217 | | IcebergTableDescriptor(const TTableDescriptor& tdesc); |
218 | | ~IcebergTableDescriptor() override; |
219 | | std::string debug_string() const override; |
220 | | |
221 | | private: |
222 | | }; |
223 | | |
224 | | class MaxComputeTableDescriptor : public TableDescriptor { |
225 | | public: |
226 | | MaxComputeTableDescriptor(const TTableDescriptor& tdesc); |
227 | | ~MaxComputeTableDescriptor() override; |
228 | | std::string debug_string() const override; |
229 | 0 | std::string region() const { return _region; } |
230 | 0 | std::string project() const { return _project; } |
231 | 0 | std::string table() const { return _table; } |
232 | 0 | std::string odps_url() const { return _odps_url; } |
233 | 0 | std::string tunnel_url() const { return _tunnel_url; } |
234 | 0 | std::string access_key() const { return _access_key; } |
235 | 0 | std::string secret_key() const { return _secret_key; } |
236 | 0 | std::string public_access() const { return _public_access; } |
237 | 0 | std::string endpoint() const { return _endpoint; } |
238 | 0 | std::string quota() const { return _quota; } |
239 | 0 | Status init_status() const { return _init_status; } |
240 | 0 | std::map<std::string, std::string> properties() const { return _props; } |
241 | | |
242 | | private: |
243 | | std::string _region; //deprecated |
244 | | std::string _project; |
245 | | std::string _table; |
246 | | std::string _odps_url; //deprecated |
247 | | std::string _tunnel_url; //deprecated |
248 | | std::string _access_key; //deprecated |
249 | | std::string _secret_key; //deprecated |
250 | | std::string _public_access; //deprecated |
251 | | std::string _endpoint; |
252 | | std::string _quota; |
253 | | std::map<std::string, std::string> _props; |
254 | | Status _init_status = Status::OK(); |
255 | | }; |
256 | | |
257 | | class TrinoConnectorTableDescriptor : public TableDescriptor { |
258 | | public: |
259 | | TrinoConnectorTableDescriptor(const TTableDescriptor& tdesc); |
260 | | ~TrinoConnectorTableDescriptor() override; |
261 | | std::string debug_string() const override; |
262 | | |
263 | | private: |
264 | | }; |
265 | | |
266 | | class EsTableDescriptor : public TableDescriptor { |
267 | | public: |
268 | | EsTableDescriptor(const TTableDescriptor& tdesc); |
269 | | ~EsTableDescriptor() override; |
270 | | std::string debug_string() const override; |
271 | | |
272 | | private: |
273 | | }; |
274 | | |
275 | | class MySQLTableDescriptor : public TableDescriptor { |
276 | | public: |
277 | | MySQLTableDescriptor(const TTableDescriptor& tdesc); |
278 | | std::string debug_string() const override; |
279 | 0 | std::string mysql_db() const { return _mysql_db; } |
280 | 0 | std::string mysql_table() const { return _mysql_table; } |
281 | 0 | std::string host() const { return _host; } |
282 | 0 | std::string port() const { return _port; } |
283 | 0 | std::string user() const { return _user; } |
284 | 0 | std::string passwd() const { return _passwd; } |
285 | 0 | std::string charset() const { return _charset; } |
286 | | |
287 | | private: |
288 | | std::string _mysql_db; |
289 | | std::string _mysql_table; |
290 | | std::string _host; |
291 | | std::string _port; |
292 | | std::string _user; |
293 | | std::string _passwd; |
294 | | std::string _charset; |
295 | | }; |
296 | | |
297 | | class JdbcTableDescriptor : public TableDescriptor { |
298 | | public: |
299 | | JdbcTableDescriptor(const TTableDescriptor& tdesc); |
300 | | std::string debug_string() const override; |
301 | 0 | int64_t jdbc_catalog_id() const { return _jdbc_catalog_id; } |
302 | 0 | const std::string& jdbc_resource_name() const { return _jdbc_resource_name; } |
303 | 0 | const std::string& jdbc_driver_url() const { return _jdbc_driver_url; } |
304 | 0 | const std::string& jdbc_driver_class() const { return _jdbc_driver_class; } |
305 | 0 | const std::string& jdbc_driver_checksum() const { return _jdbc_driver_checksum; } |
306 | 0 | const std::string& jdbc_url() const { return _jdbc_url; } |
307 | 0 | const std::string& jdbc_table_name() const { return _jdbc_table_name; } |
308 | 0 | const std::string& jdbc_user() const { return _jdbc_user; } |
309 | 0 | const std::string& jdbc_passwd() const { return _jdbc_passwd; } |
310 | 0 | int32_t connection_pool_min_size() const { return _connection_pool_min_size; } |
311 | 0 | int32_t connection_pool_max_size() const { return _connection_pool_max_size; } |
312 | 0 | int32_t connection_pool_max_wait_time() const { return _connection_pool_max_wait_time; } |
313 | 0 | int32_t connection_pool_max_life_time() const { return _connection_pool_max_life_time; } |
314 | 0 | bool connection_pool_keep_alive() const { return _connection_pool_keep_alive; } |
315 | | |
316 | | private: |
317 | | int64_t _jdbc_catalog_id; |
318 | | std::string _jdbc_resource_name; |
319 | | std::string _jdbc_driver_url; |
320 | | std::string _jdbc_driver_class; |
321 | | std::string _jdbc_driver_checksum; |
322 | | std::string _jdbc_url; |
323 | | std::string _jdbc_table_name; |
324 | | std::string _jdbc_user; |
325 | | std::string _jdbc_passwd; |
326 | | int32_t _connection_pool_min_size; |
327 | | int32_t _connection_pool_max_size; |
328 | | int32_t _connection_pool_max_wait_time; |
329 | | int32_t _connection_pool_max_life_time; |
330 | | bool _connection_pool_keep_alive; |
331 | | }; |
332 | | |
333 | | class RemoteDorisTableDescriptor : public TableDescriptor { |
334 | | public: |
335 | | RemoteDorisTableDescriptor(const TTableDescriptor& tdesc); |
336 | | ~RemoteDorisTableDescriptor() override; |
337 | | std::string debug_string() const override; |
338 | | |
339 | | private: |
340 | | }; |
341 | | |
342 | | class TupleDescriptor { |
343 | | public: |
344 | | TupleDescriptor(TupleDescriptor&&) = delete; |
345 | | void operator=(const TupleDescriptor&) = delete; |
346 | | |
347 | 293k | MOCK_DEFINE(virtual) ~TupleDescriptor() { |
348 | 293k | if (_own_slots) { |
349 | 13 | for (SlotDescriptor* slot : _slots) { |
350 | 13 | delete slot; |
351 | 13 | } |
352 | 4 | } |
353 | 293k | } |
354 | | |
355 | | MOCK_DEFINE(TupleDescriptor() : _id {0} {};) |
356 | | |
357 | 0 | int num_materialized_slots() const { return _num_materialized_slots; } |
358 | 826k | MOCK_FUNCTION const std::vector<SlotDescriptor*>& slots() const { return _slots; } |
359 | | int get_column_id(SlotId slot_id) const; |
360 | | |
361 | 0 | bool has_varlen_slots() const { return _has_varlen_slots; } |
362 | 0 | const TableDescriptor* table_desc() const { return _table_desc; } |
363 | | |
364 | 8 | TupleId id() const { return _id; } |
365 | | |
366 | | std::string debug_string() const; |
367 | | |
368 | | void to_protobuf(PTupleDescriptor* ptuple) const; |
369 | | |
370 | | private: |
371 | | friend class DescriptorTbl; |
372 | | friend class SchemaScanner; |
373 | | friend class OlapTableSchemaParam; |
374 | | friend class PInternalServiceImpl; |
375 | | friend class RowIdStorageReader; |
376 | | friend class TabletSchema; |
377 | | |
378 | | const TupleId _id; |
379 | | TableDescriptor* _table_desc = nullptr; |
380 | | int _num_materialized_slots; |
381 | | std::vector<SlotDescriptor*> _slots; // contains all slots |
382 | | |
383 | | // Provide quick way to check if there are variable length slots. |
384 | | // True if _string_slots or _collection_slots have entries. |
385 | | bool _has_varlen_slots; |
386 | | bool _own_slots = false; |
387 | | |
388 | | TupleDescriptor(const TTupleDescriptor& tdesc, bool own_slot = false); |
389 | | TupleDescriptor(const PTupleDescriptor& tdesc, bool own_slot = false); |
390 | | |
391 | | void add_slot(SlotDescriptor* slot); |
392 | | }; |
393 | | |
394 | | class DescriptorTbl { |
395 | | public: |
396 | | #ifdef BE_TEST |
397 | 204k | DescriptorTbl() = default; |
398 | 205k | virtual ~DescriptorTbl() = default; |
399 | | #endif |
400 | | |
401 | | // Creates a descriptor tbl within 'pool' from thrift_tbl and returns it via 'tbl'. |
402 | | // Returns OK on success, otherwise error (in which case 'tbl' will be unset). |
403 | | static Status create(ObjectPool* pool, const TDescriptorTable& thrift_tbl, DescriptorTbl** tbl); |
404 | | |
405 | | TableDescriptor* get_table_descriptor(TableId id) const; |
406 | | TupleDescriptor* get_tuple_descriptor(TupleId id) const; |
407 | | MOCK_FUNCTION SlotDescriptor* get_slot_descriptor(SlotId id) const; |
408 | 0 | const std::vector<TTupleId>& get_row_tuples() const { return _row_tuples; } |
409 | | |
410 | | // return all registered tuple descriptors |
411 | 88 | std::vector<TupleDescriptor*> get_tuple_descs() const { |
412 | 88 | std::vector<TupleDescriptor*> descs; |
413 | | |
414 | 210 | for (auto it : _tuple_desc_map) { |
415 | 210 | descs.push_back(it.second); |
416 | 210 | } |
417 | | |
418 | 88 | return descs; |
419 | 88 | } |
420 | | |
421 | | std::string debug_string() const; |
422 | | |
423 | | private: |
424 | | using TableDescriptorMap = std::unordered_map<TableId, TableDescriptor*>; |
425 | | using TupleDescriptorMap = std::unordered_map<TupleId, TupleDescriptor*>; |
426 | | using SlotDescriptorMap = std::unordered_map<SlotId, SlotDescriptor*>; |
427 | | |
428 | | TableDescriptorMap _tbl_desc_map; |
429 | | TupleDescriptorMap _tuple_desc_map; |
430 | | SlotDescriptorMap _slot_desc_map; |
431 | | std::vector<TTupleId> _row_tuples; |
432 | | |
433 | | #ifndef BE_TEST |
434 | | DescriptorTbl() = default; |
435 | | #endif |
436 | | }; |
437 | | |
438 | | // Describes the ordered tuples whose slots form an operator's block layout. |
439 | | class RowDescriptor { |
440 | | public: |
441 | | RowDescriptor(const DescriptorTbl& desc_tbl, const std::vector<TTupleId>& row_tuples); |
442 | | |
443 | | RowDescriptor(TupleDescriptor* tuple_desc); |
444 | | |
445 | | // Empty layout for expressions that do not reference slots. |
446 | 146k | RowDescriptor() = default; |
447 | | |
448 | | MOCK_DEFINE(virtual ~RowDescriptor() = default;) |
449 | | |
450 | | int num_slots() const; |
451 | | |
452 | | // Return descriptors for all tuples in this row, in order of appearance. |
453 | 361k | MOCK_FUNCTION const std::vector<TupleDescriptor*>& tuple_descriptors() const { |
454 | 361k | return _tuple_desc_map; |
455 | 361k | } |
456 | | |
457 | | std::string debug_string() const; |
458 | | |
459 | | int get_column_id(int slot_id) const; |
460 | | |
461 | | private: |
462 | | // Tuples in block column order; descriptors are owned elsewhere. |
463 | | std::vector<TupleDescriptor*> _tuple_desc_map; |
464 | | }; |
465 | | } // namespace doris |