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_decimal.h" |
30 | | #include "core/column/column_dictionary.h" |
31 | | #include "core/column/column_map.h" |
32 | | #include "core/column/column_nullable.h" |
33 | | #include "core/column/column_string.h" |
34 | | #include "core/column/column_struct.h" |
35 | | #include "core/column/column_vector.h" |
36 | | #include "core/data_type/data_type.h" |
37 | | #include "core/data_type/data_type_factory.hpp" |
38 | | #include "core/data_type/define_primitive_type.h" |
39 | | #include "core/types.h" |
40 | | #include "storage/olap_common.h" |
41 | | #include "util/trace.h" |
42 | | |
43 | | namespace doris { |
44 | | |
45 | 5 | Schema::Schema(const Schema& other) { |
46 | 5 | _copy_from(other); |
47 | 5 | } |
48 | | |
49 | 0 | Schema& Schema::operator=(const Schema& other) { |
50 | 0 | if (this != &other) { |
51 | 0 | _copy_from(other); |
52 | 0 | } |
53 | 0 | return *this; |
54 | 0 | } |
55 | | |
56 | 5 | void Schema::_copy_from(const Schema& other) { |
57 | 5 | _col_ids = other._col_ids; |
58 | 5 | _num_key_columns = other._num_key_columns; |
59 | 5 | _delete_sign_idx = other._delete_sign_idx; |
60 | 5 | _has_sequence_col = other._has_sequence_col; |
61 | 5 | _rowid_col_idx = other._rowid_col_idx; |
62 | 5 | _version_col_idx = other._version_col_idx; |
63 | 5 | _lsn_col_idx = other._lsn_col_idx; |
64 | 5 | _tso_col_idx = other._tso_col_idx; |
65 | | |
66 | 5 | _cols.resize(other._cols.size()); |
67 | 15 | for (auto cid : _col_ids) { |
68 | 15 | _cols[cid] = other._cols[cid]; |
69 | 15 | } |
70 | 5 | } |
71 | | |
72 | | void Schema::_init(const std::vector<TabletColumnPtr>& cols, const std::vector<ColumnId>& col_ids, |
73 | 10.4M | size_t num_key_columns) { |
74 | 10.4M | _col_ids = col_ids; |
75 | 10.4M | _num_key_columns = num_key_columns; |
76 | | |
77 | 10.4M | _cols.resize(cols.size()); |
78 | | |
79 | 10.4M | std::unordered_set<uint32_t> col_id_set(col_ids.begin(), col_ids.end()); |
80 | 150M | for (int cid = 0; cid < cols.size(); ++cid) { |
81 | 139M | if (col_id_set.find(cid) == col_id_set.end()) { |
82 | 56.8M | continue; |
83 | 56.8M | } |
84 | 83.1M | _cols[cid] = cols[cid]; |
85 | 83.1M | } |
86 | 10.4M | } |
87 | | |
88 | 10.4M | Schema::~Schema() = default; |
89 | | |
90 | 44.1M | DataTypePtr Schema::get_data_type_ptr(const TabletColumn& column) { |
91 | 44.1M | return DataTypeFactory::instance().create_data_type(column); |
92 | 44.1M | } |
93 | | |
94 | | IColumn::MutablePtr Schema::get_predicate_column_ptr(const DataTypePtr& data_type, |
95 | 1.21M | const ReaderType reader_type) { |
96 | | // Low-cardinality dictionary optimization substitutes a ColumnDictI32 for the |
97 | | // canonical string column during query reads. Every other case just materializes |
98 | | // the data type's own canonical column (which already wraps nullable for us). |
99 | 1.21M | if (config::enable_low_cardinality_optimize && reader_type == ReaderType::READER_QUERY && |
100 | 1.21M | is_string_type(data_type->get_primitive_type())) { |
101 | 13.1k | IColumn::MutablePtr ptr = doris::ColumnDictI32::create(); |
102 | 13.1k | if (data_type->is_nullable()) { |
103 | 5.71k | return doris::ColumnNullable::create(std::move(ptr), doris::ColumnUInt8::create()); |
104 | 5.71k | } |
105 | 7.43k | return ptr; |
106 | 13.1k | } |
107 | 1.20M | return data_type->create_column(); |
108 | 1.21M | } |
109 | | |
110 | | } // namespace doris |