be/src/storage/schema.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 | | |
18 | | #include "storage/schema.h" |
19 | | |
20 | | #include <glog/logging.h> |
21 | | |
22 | | #include <boost/iterator/iterator_facade.hpp> |
23 | | #include <ostream> |
24 | | #include <unordered_set> |
25 | | #include <utility> |
26 | | |
27 | | #include "common/config.h" |
28 | | #include "core/column/column_array.h" |
29 | | #include "core/column/column_dictionary.h" |
30 | | #include "core/column/column_map.h" |
31 | | #include "core/column/column_nullable.h" |
32 | | #include "core/column/column_struct.h" |
33 | | #include "core/column/predicate_column.h" |
34 | | #include "core/data_type/data_type.h" |
35 | | #include "core/data_type/data_type_factory.hpp" |
36 | | #include "core/data_type/define_primitive_type.h" |
37 | | #include "core/types.h" |
38 | | #include "storage/olap_common.h" |
39 | | #include "util/trace.h" |
40 | | |
41 | | namespace doris { |
42 | | |
43 | 5 | Schema::Schema(const Schema& other) { |
44 | 5 | _copy_from(other); |
45 | 5 | } |
46 | | |
47 | 0 | Schema& Schema::operator=(const Schema& other) { |
48 | 0 | if (this != &other) { |
49 | 0 | _copy_from(other); |
50 | 0 | } |
51 | 0 | return *this; |
52 | 0 | } |
53 | | |
54 | 5 | void Schema::_copy_from(const Schema& other) { |
55 | 5 | _col_ids = other._col_ids; |
56 | 5 | _column_id_to_index = other._column_id_to_index; |
57 | 5 | _num_key_columns = other._num_key_columns; |
58 | 5 | _delete_sign_idx = other._delete_sign_idx; |
59 | 5 | _has_sequence_col = other._has_sequence_col; |
60 | 5 | _rowid_col_idx = other._rowid_col_idx; |
61 | 5 | _version_col_idx = other._version_col_idx; |
62 | 5 | _lsn_col_idx = other._lsn_col_idx; |
63 | 5 | _tso_col_idx = other._tso_col_idx; |
64 | | |
65 | 5 | _cols.resize(other._cols.size()); |
66 | 15 | for (auto cid : _col_ids) { |
67 | 15 | _cols[cid] = other._cols[cid]; |
68 | 15 | } |
69 | 5 | } |
70 | | |
71 | | void Schema::_init(const std::vector<TabletColumnPtr>& cols, const std::vector<ColumnId>& col_ids, |
72 | 11.7M | size_t num_key_columns) { |
73 | 11.7M | _col_ids = col_ids; |
74 | 11.7M | _num_key_columns = num_key_columns; |
75 | | |
76 | 11.7M | _cols.resize(cols.size()); |
77 | | |
78 | 11.7M | std::unordered_set<uint32_t> col_id_set(col_ids.begin(), col_ids.end()); |
79 | 11.7M | _column_id_to_index.assign(cols.size(), -1); |
80 | 103M | for (size_t i = 0; i < col_ids.size(); ++i) { |
81 | 92.0M | _column_id_to_index[col_ids[i]] = static_cast<int>(i); |
82 | 92.0M | } |
83 | | |
84 | 170M | for (int cid = 0; cid < cols.size(); ++cid) { |
85 | 158M | if (col_id_set.find(cid) == col_id_set.end()) { |
86 | 66.6M | continue; |
87 | 66.6M | } |
88 | 91.7M | _cols[cid] = cols[cid]; |
89 | 91.7M | } |
90 | 11.7M | } |
91 | | |
92 | 11.7M | Schema::~Schema() = default; |
93 | | |
94 | 53.5M | DataTypePtr Schema::get_data_type_ptr(const TabletColumn& column) { |
95 | 53.5M | return DataTypeFactory::instance().create_data_type(column); |
96 | 53.5M | } |
97 | | |
98 | | IColumn::MutablePtr Schema::get_predicate_column_ptr(const FieldType& type, bool is_nullable, |
99 | 1.49M | const ReaderType reader_type) { |
100 | 1.49M | IColumn::MutablePtr ptr = nullptr; |
101 | 1.49M | switch (type) { |
102 | 211 | case FieldType::OLAP_FIELD_TYPE_BOOL: |
103 | 211 | ptr = doris::PredicateColumnType<TYPE_BOOLEAN>::create(); |
104 | 211 | break; |
105 | 1.44M | case FieldType::OLAP_FIELD_TYPE_TINYINT: |
106 | 1.44M | ptr = doris::PredicateColumnType<TYPE_TINYINT>::create(); |
107 | 1.44M | break; |
108 | 1.12k | case FieldType::OLAP_FIELD_TYPE_SMALLINT: |
109 | 1.12k | ptr = doris::PredicateColumnType<TYPE_SMALLINT>::create(); |
110 | 1.12k | break; |
111 | 19.4k | case FieldType::OLAP_FIELD_TYPE_INT: |
112 | 19.4k | ptr = doris::PredicateColumnType<TYPE_INT>::create(); |
113 | 19.4k | break; |
114 | 27 | case FieldType::OLAP_FIELD_TYPE_FLOAT: |
115 | 27 | ptr = doris::PredicateColumnType<TYPE_FLOAT>::create(); |
116 | 27 | break; |
117 | 193 | case FieldType::OLAP_FIELD_TYPE_DOUBLE: |
118 | 193 | ptr = doris::PredicateColumnType<TYPE_DOUBLE>::create(); |
119 | 193 | break; |
120 | 2.92k | case FieldType::OLAP_FIELD_TYPE_BIGINT: |
121 | 2.92k | ptr = doris::PredicateColumnType<TYPE_BIGINT>::create(); |
122 | 2.92k | break; |
123 | 589 | case FieldType::OLAP_FIELD_TYPE_LARGEINT: |
124 | 589 | ptr = doris::PredicateColumnType<TYPE_LARGEINT>::create(); |
125 | 589 | break; |
126 | 398 | case FieldType::OLAP_FIELD_TYPE_DATE: |
127 | 398 | ptr = doris::PredicateColumnType<TYPE_DATE>::create(); |
128 | 398 | break; |
129 | 2.62k | case FieldType::OLAP_FIELD_TYPE_DATEV2: |
130 | 2.62k | ptr = doris::PredicateColumnType<TYPE_DATEV2>::create(); |
131 | 2.62k | break; |
132 | 820 | case FieldType::OLAP_FIELD_TYPE_DATETIMEV2: |
133 | 820 | ptr = doris::PredicateColumnType<TYPE_DATETIMEV2>::create(); |
134 | 820 | break; |
135 | 264 | case FieldType::OLAP_FIELD_TYPE_DATETIME: |
136 | 264 | ptr = doris::PredicateColumnType<TYPE_DATETIME>::create(); |
137 | 264 | break; |
138 | 3.47k | case FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ: |
139 | 3.47k | ptr = doris::PredicateColumnType<TYPE_TIMESTAMPTZ>::create(); |
140 | 3.47k | break; |
141 | 932 | case FieldType::OLAP_FIELD_TYPE_CHAR: |
142 | 934 | if (config::enable_low_cardinality_optimize && reader_type == ReaderType::READER_QUERY) { |
143 | 934 | ptr = doris::ColumnDictI32::create(type); |
144 | 18.4E | } else { |
145 | 18.4E | ptr = doris::PredicateColumnType<TYPE_CHAR>::create(); |
146 | 18.4E | } |
147 | 932 | break; |
148 | 11.5k | case FieldType::OLAP_FIELD_TYPE_VARCHAR: |
149 | 12.9k | case FieldType::OLAP_FIELD_TYPE_STRING: |
150 | 13.0k | case FieldType::OLAP_FIELD_TYPE_JSONB: |
151 | 13.0k | if (config::enable_low_cardinality_optimize && reader_type == ReaderType::READER_QUERY) { |
152 | 13.0k | ptr = doris::ColumnDictI32::create(type); |
153 | 13.0k | } else { |
154 | 36 | ptr = doris::PredicateColumnType<TYPE_STRING>::create(); |
155 | 36 | } |
156 | 13.0k | break; |
157 | 1 | case FieldType::OLAP_FIELD_TYPE_DECIMAL: |
158 | 1 | ptr = doris::PredicateColumnType<TYPE_DECIMALV2>::create(); |
159 | 1 | break; |
160 | 153 | case FieldType::OLAP_FIELD_TYPE_DECIMAL32: |
161 | 153 | ptr = doris::PredicateColumnType<TYPE_DECIMAL32>::create(); |
162 | 153 | break; |
163 | 252 | case FieldType::OLAP_FIELD_TYPE_DECIMAL64: |
164 | 252 | ptr = doris::PredicateColumnType<TYPE_DECIMAL64>::create(); |
165 | 252 | break; |
166 | 785 | case FieldType::OLAP_FIELD_TYPE_DECIMAL128I: |
167 | 785 | ptr = doris::PredicateColumnType<TYPE_DECIMAL128I>::create(); |
168 | 785 | break; |
169 | 182 | case FieldType::OLAP_FIELD_TYPE_DECIMAL256: |
170 | 182 | ptr = doris::PredicateColumnType<TYPE_DECIMAL256>::create(); |
171 | 182 | break; |
172 | 91 | case FieldType::OLAP_FIELD_TYPE_IPV4: |
173 | 91 | ptr = doris::PredicateColumnType<TYPE_IPV4>::create(); |
174 | 91 | break; |
175 | 92 | case FieldType::OLAP_FIELD_TYPE_IPV6: |
176 | 92 | ptr = doris::PredicateColumnType<TYPE_IPV6>::create(); |
177 | 92 | break; |
178 | 0 | default: |
179 | 0 | throw Exception( |
180 | 0 | ErrorCode::SCHEMA_SCHEMA_FIELD_INVALID, |
181 | 0 | fmt::format("Unexpected type when choosing predicate column, type={}", int(type))); |
182 | 1.49M | } |
183 | | |
184 | 1.49M | if (is_nullable) { |
185 | 23.9k | return doris::ColumnNullable::create(std::move(ptr), doris::ColumnUInt8::create()); |
186 | 23.9k | } |
187 | 1.47M | return ptr; |
188 | 1.49M | } |
189 | | |
190 | | } // namespace doris |