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 | | |
18 | | #pragma once |
19 | | |
20 | | #include <stddef.h> |
21 | | #include <stdint.h> |
22 | | |
23 | | #include <algorithm> |
24 | | #include <cstdint> |
25 | | #include <memory> |
26 | | #include <string> |
27 | | #include <vector> |
28 | | |
29 | | #include "common/consts.h" |
30 | | #include "core/column/column.h" |
31 | | #include "exprs/aggregate/aggregate_function.h" |
32 | | #include "io/io_common.h" |
33 | | #include "runtime/thread_context.h" |
34 | | #include "storage/olap_common.h" |
35 | | #include "storage/tablet/tablet_schema.h" |
36 | | #include "storage/utils.h" |
37 | | |
38 | | namespace doris { |
39 | | |
40 | | // The class is used to represent row's format in memory. Each row contains |
41 | | // multiple columns, some of which are key-columns (the rest are value-columns). |
42 | | // NOTE: If both key-columns and value-columns exist, then the key-columns |
43 | | // must be placed before value-columns. |
44 | | // |
45 | | // To compare two rows whose schemas are different, but they are from the same origin |
46 | | // we store all column schema maybe accessed here. And default access through column id |
47 | | class Schema; |
48 | | using SchemaSPtr = std::shared_ptr<const Schema>; |
49 | | class Schema { |
50 | | public: |
51 | | // All the columns of one table may exist in the columns param, but col_ids is only a subset. |
52 | 13.1M | Schema(const std::vector<TabletColumnPtr>& columns, const std::vector<ColumnId>& col_ids) { |
53 | 13.1M | size_t num_key_columns = 0; |
54 | 192M | for (int i = 0; i < columns.size(); ++i) { |
55 | 178M | if (columns[i]->is_key()) { |
56 | 67.7M | ++num_key_columns; |
57 | 67.7M | } |
58 | 178M | if (columns[i]->name() == DELETE_SIGN) { |
59 | 7.92M | _delete_sign_idx = i; |
60 | 7.92M | } |
61 | 178M | if (columns[i]->name() == BeConsts::ROWID_COL || |
62 | 178M | columns[i]->name().starts_with(BeConsts::GLOBAL_ROWID_COL)) { |
63 | 34.4k | _rowid_col_idx = i; |
64 | 34.4k | } |
65 | 178M | if (columns[i]->name() == VERSION_COL) { |
66 | 7.92M | _version_col_idx = i; |
67 | 7.92M | } |
68 | 178M | if (columns[i]->name() == BINLOG_LSN_COL) { |
69 | 0 | _lsn_col_idx = i; |
70 | 0 | } |
71 | 178M | if (columns[i]->name() == BINLOG_OP_COL) { |
72 | 0 | _op_col_idx = i; |
73 | 0 | } |
74 | 178M | if (columns[i]->name() == BINLOG_TSO_COL) { |
75 | 0 | _tso_col_idx = i; |
76 | 0 | } |
77 | 178M | } |
78 | 13.1M | _init(columns, col_ids, num_key_columns); |
79 | 13.1M | } |
80 | | |
81 | | Schema(const Schema&); |
82 | | Schema& operator=(const Schema& other); |
83 | | |
84 | | ~Schema(); |
85 | | |
86 | | static DataTypePtr get_data_type_ptr(const TabletColumn& column); |
87 | | |
88 | | static IColumn::MutablePtr get_predicate_column_ptr(const DataTypePtr& data_type, |
89 | | const ReaderType reader_type); |
90 | | |
91 | 79.3M | const std::vector<TabletColumnPtr>& columns() const { return _cols; } |
92 | | |
93 | 260M | const TabletColumn* column(ColumnId cid) const { return _cols[cid].get(); } |
94 | | |
95 | 117k | size_t num_key_columns() const { return _num_key_columns; } |
96 | | |
97 | 4.15M | size_t num_columns() const { return _cols.size(); } |
98 | 71.8M | size_t num_column_ids() const { return _col_ids.size(); } |
99 | 85.5M | const std::vector<ColumnId>& column_ids() const { return _col_ids; } |
100 | 85.1M | ColumnId column_id(size_t index) const { return _col_ids[index]; } |
101 | 0 | int32_t delete_sign_idx() const { return _delete_sign_idx; } |
102 | 0 | bool has_sequence_col() const { return _has_sequence_col; } |
103 | 2.07M | int32_t rowid_col_idx() const { return _rowid_col_idx; } |
104 | 1.45M | int32_t version_col_idx() const { return _version_col_idx; } |
105 | 0 | int32_t lsn_col_idx() const { return _lsn_col_idx; } |
106 | 0 | int32_t op_col_idx() const { return _op_col_idx; } |
107 | 0 | int32_t tso_col_idx() const { return _tso_col_idx; } |
108 | | // Don't use. |
109 | | // TODO: memory size of Schema cannot be accurately tracked. |
110 | | // In some places, temporarily use num_columns() as Schema size. |
111 | 0 | int64_t mem_size() const { return _mem_size; } |
112 | | |
113 | | private: |
114 | | void _init(const std::vector<TabletColumnPtr>& cols, const std::vector<ColumnId>& col_ids, |
115 | | size_t num_key_columns); |
116 | | |
117 | | void _copy_from(const Schema& other); |
118 | | |
119 | | // NOTE: The ColumnId here represents the sequential index number (starting from 0) of |
120 | | // a column in current row, not the unique id-identifier of each column |
121 | | std::vector<ColumnId> _col_ids; |
122 | | // NOTE: _cols[cid] can only be accessed when the cid is |
123 | | // contained in _col_ids |
124 | | std::vector<TabletColumnPtr> _cols; |
125 | | |
126 | | size_t _num_key_columns; |
127 | | int32_t _delete_sign_idx = -1; |
128 | | bool _has_sequence_col = false; |
129 | | int32_t _rowid_col_idx = -1; |
130 | | int32_t _version_col_idx = -1; |
131 | | int32_t _lsn_col_idx = -1; |
132 | | int32_t _op_col_idx = -1; |
133 | | int32_t _tso_col_idx = -1; |
134 | | int64_t _mem_size = 0; |
135 | | }; |
136 | | |
137 | | } // namespace doris |