Coverage Report

Created: 2026-06-29 16:52

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