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 | 3.63M | Schema::Schema(const Schema& other) { |
44 | 3.63M | _copy_from(other); |
45 | 3.63M | } |
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 | 3.65M | void Schema::_copy_from(const Schema& other) { |
55 | 3.65M | _col_ids = other._col_ids; |
56 | 3.65M | _unique_ids = other._unique_ids; |
57 | 3.65M | _num_key_columns = other._num_key_columns; |
58 | 3.65M | _delete_sign_idx = other._delete_sign_idx; |
59 | 3.65M | _has_sequence_col = other._has_sequence_col; |
60 | 3.65M | _rowid_col_idx = other._rowid_col_idx; |
61 | 3.65M | _version_col_idx = other._version_col_idx; |
62 | 3.65M | _lsn_col_idx = other._lsn_col_idx; |
63 | 3.65M | _tso_col_idx = other._tso_col_idx; |
64 | 3.65M | _mem_size = other._mem_size; |
65 | | |
66 | 3.65M | _cols.resize(other._cols.size()); |
67 | 6.13M | for (auto cid : _col_ids) { |
68 | 6.13M | _cols[cid] = other._cols[cid]; |
69 | 6.13M | } |
70 | 3.65M | } |
71 | | |
72 | | void Schema::_init(const std::vector<TabletColumnPtr>& cols, const std::vector<ColumnId>& col_ids, |
73 | 8.40M | size_t num_key_columns) { |
74 | 8.40M | _col_ids = col_ids; |
75 | 8.40M | _num_key_columns = num_key_columns; |
76 | | |
77 | 8.40M | _cols.resize(cols.size()); |
78 | | |
79 | 8.40M | std::unordered_set<uint32_t> col_id_set(col_ids.begin(), col_ids.end()); |
80 | 124M | for (int cid = 0; cid < cols.size(); ++cid) { |
81 | 116M | if (col_id_set.find(cid) == col_id_set.end()) { |
82 | 36.5M | continue; |
83 | 36.5M | } |
84 | 79.9M | _cols[cid] = cols[cid]; |
85 | 79.9M | } |
86 | 8.40M | } |
87 | | |
88 | 12.0M | Schema::~Schema() = default; |
89 | | |
90 | 45.4M | DataTypePtr Schema::get_data_type_ptr(const TabletColumn& column) { |
91 | 45.4M | return DataTypeFactory::instance().create_data_type(column); |
92 | 45.4M | } |
93 | | |
94 | | IColumn::MutablePtr Schema::get_predicate_column_ptr(const FieldType& type, bool is_nullable, |
95 | 1.24M | const ReaderType reader_type) { |
96 | 1.24M | IColumn::MutablePtr ptr = nullptr; |
97 | 1.24M | switch (type) { |
98 | 168 | case FieldType::OLAP_FIELD_TYPE_BOOL: |
99 | 168 | ptr = doris::PredicateColumnType<TYPE_BOOLEAN>::create(); |
100 | 168 | break; |
101 | 1.19M | case FieldType::OLAP_FIELD_TYPE_TINYINT: |
102 | 1.19M | ptr = doris::PredicateColumnType<TYPE_TINYINT>::create(); |
103 | 1.19M | break; |
104 | 1.25k | case FieldType::OLAP_FIELD_TYPE_SMALLINT: |
105 | 1.25k | ptr = doris::PredicateColumnType<TYPE_SMALLINT>::create(); |
106 | 1.25k | break; |
107 | 21.4k | case FieldType::OLAP_FIELD_TYPE_INT: |
108 | 21.4k | ptr = doris::PredicateColumnType<TYPE_INT>::create(); |
109 | 21.4k | break; |
110 | 28 | case FieldType::OLAP_FIELD_TYPE_FLOAT: |
111 | 28 | ptr = doris::PredicateColumnType<TYPE_FLOAT>::create(); |
112 | 28 | break; |
113 | 222 | case FieldType::OLAP_FIELD_TYPE_DOUBLE: |
114 | 222 | ptr = doris::PredicateColumnType<TYPE_DOUBLE>::create(); |
115 | 222 | break; |
116 | 2.03k | case FieldType::OLAP_FIELD_TYPE_BIGINT: |
117 | 2.03k | ptr = doris::PredicateColumnType<TYPE_BIGINT>::create(); |
118 | 2.03k | break; |
119 | 507 | case FieldType::OLAP_FIELD_TYPE_LARGEINT: |
120 | 507 | ptr = doris::PredicateColumnType<TYPE_LARGEINT>::create(); |
121 | 507 | break; |
122 | 543 | case FieldType::OLAP_FIELD_TYPE_DATE: |
123 | 543 | ptr = doris::PredicateColumnType<TYPE_DATE>::create(); |
124 | 543 | break; |
125 | 2.61k | case FieldType::OLAP_FIELD_TYPE_DATEV2: |
126 | 2.61k | ptr = doris::PredicateColumnType<TYPE_DATEV2>::create(); |
127 | 2.61k | break; |
128 | 799 | case FieldType::OLAP_FIELD_TYPE_DATETIMEV2: |
129 | 799 | ptr = doris::PredicateColumnType<TYPE_DATETIMEV2>::create(); |
130 | 799 | break; |
131 | 351 | case FieldType::OLAP_FIELD_TYPE_DATETIME: |
132 | 351 | ptr = doris::PredicateColumnType<TYPE_DATETIME>::create(); |
133 | 351 | break; |
134 | 3.63k | case FieldType::OLAP_FIELD_TYPE_TIMESTAMPTZ: |
135 | 3.63k | ptr = doris::PredicateColumnType<TYPE_TIMESTAMPTZ>::create(); |
136 | 3.63k | break; |
137 | 1.24k | case FieldType::OLAP_FIELD_TYPE_CHAR: |
138 | 1.24k | if (config::enable_low_cardinality_optimize && reader_type == ReaderType::READER_QUERY) { |
139 | 1.23k | ptr = doris::ColumnDictI32::create(type); |
140 | 1.23k | } else { |
141 | 3 | ptr = doris::PredicateColumnType<TYPE_CHAR>::create(); |
142 | 3 | } |
143 | 1.24k | break; |
144 | 0 | case FieldType::OLAP_FIELD_TYPE_VARCHAR: |
145 | 12.4k | case FieldType::OLAP_FIELD_TYPE_STRING: |
146 | 12.5k | case FieldType::OLAP_FIELD_TYPE_JSONB: |
147 | 12.5k | if (config::enable_low_cardinality_optimize && reader_type == ReaderType::READER_QUERY) { |
148 | 12.3k | ptr = doris::ColumnDictI32::create(type); |
149 | 12.3k | } else { |
150 | 161 | ptr = doris::PredicateColumnType<TYPE_STRING>::create(); |
151 | 161 | } |
152 | 12.5k | break; |
153 | 1 | case FieldType::OLAP_FIELD_TYPE_DECIMAL: |
154 | 1 | ptr = doris::PredicateColumnType<TYPE_DECIMALV2>::create(); |
155 | 1 | break; |
156 | 143 | case FieldType::OLAP_FIELD_TYPE_DECIMAL32: |
157 | 143 | ptr = doris::PredicateColumnType<TYPE_DECIMAL32>::create(); |
158 | 143 | break; |
159 | 269 | case FieldType::OLAP_FIELD_TYPE_DECIMAL64: |
160 | 269 | ptr = doris::PredicateColumnType<TYPE_DECIMAL64>::create(); |
161 | 269 | break; |
162 | 1.00k | case FieldType::OLAP_FIELD_TYPE_DECIMAL128I: |
163 | 1.00k | ptr = doris::PredicateColumnType<TYPE_DECIMAL128I>::create(); |
164 | 1.00k | break; |
165 | 180 | case FieldType::OLAP_FIELD_TYPE_DECIMAL256: |
166 | 180 | ptr = doris::PredicateColumnType<TYPE_DECIMAL256>::create(); |
167 | 180 | break; |
168 | 92 | case FieldType::OLAP_FIELD_TYPE_IPV4: |
169 | 92 | ptr = doris::PredicateColumnType<TYPE_IPV4>::create(); |
170 | 92 | break; |
171 | 93 | case FieldType::OLAP_FIELD_TYPE_IPV6: |
172 | 93 | ptr = doris::PredicateColumnType<TYPE_IPV6>::create(); |
173 | 93 | break; |
174 | 0 | default: |
175 | 0 | throw Exception( |
176 | 0 | ErrorCode::SCHEMA_SCHEMA_FIELD_INVALID, |
177 | 0 | fmt::format("Unexpected type when choosing predicate column, type={}", int(type))); |
178 | 1.24M | } |
179 | | |
180 | 1.24M | if (is_nullable) { |
181 | 24.1k | return doris::ColumnNullable::create(std::move(ptr), doris::ColumnUInt8::create()); |
182 | 24.1k | } |
183 | 1.22M | return ptr; |
184 | 1.24M | } |
185 | | |
186 | | } // namespace doris |