Coverage Report

Created: 2026-05-15 14:14

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