Coverage Report

Created: 2026-07-21 18:50

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_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
4
Schema::Schema(const Schema& other) {
46
4
    _copy_from(other);
47
4
}
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
4
void Schema::_copy_from(const Schema& other) {
57
4
    _col_ids = other._col_ids;
58
4
    _num_key_columns = other._num_key_columns;
59
4
    _delete_sign_idx = other._delete_sign_idx;
60
4
    _has_sequence_col = other._has_sequence_col;
61
4
    _rowid_col_idx = other._rowid_col_idx;
62
4
    _version_col_idx = other._version_col_idx;
63
64
4
    _cols.resize(other._cols.size());
65
12
    for (auto cid : _col_ids) {
66
12
        _cols[cid] = other._cols[cid];
67
12
    }
68
4
}
69
70
void Schema::_init(const std::vector<TabletColumnPtr>& cols, const std::vector<ColumnId>& col_ids,
71
7.01k
                   size_t num_key_columns) {
72
7.01k
    _col_ids = col_ids;
73
7.01k
    _num_key_columns = num_key_columns;
74
75
7.01k
    _cols.resize(cols.size());
76
77
7.01k
    std::unordered_set<uint32_t> col_id_set(col_ids.begin(), col_ids.end());
78
68.8k
    for (int cid = 0; cid < cols.size(); ++cid) {
79
61.8k
        if (col_id_set.find(cid) == col_id_set.end()) {
80
42.3k
            continue;
81
42.3k
        }
82
19.4k
        _cols[cid] = cols[cid];
83
19.4k
    }
84
7.01k
}
85
86
7.01k
Schema::~Schema() = default;
87
88
68.8k
DataTypePtr Schema::get_data_type_ptr(const TabletColumn& column) {
89
68.8k
    return DataTypeFactory::instance().create_data_type(column);
90
68.8k
}
91
92
IColumn::MutablePtr Schema::get_predicate_column_ptr(const DataTypePtr& data_type,
93
486
                                                     const ReaderType reader_type) {
94
    // Low-cardinality dictionary optimization substitutes a ColumnDictI32 for the
95
    // canonical string column during query reads. Every other case just materializes
96
    // the data type's own canonical column (which already wraps nullable for us).
97
486
    if (config::enable_low_cardinality_optimize && reader_type == ReaderType::READER_QUERY &&
98
486
        is_string_type(data_type->get_primitive_type())) {
99
5
        IColumn::MutablePtr ptr = doris::ColumnDictI32::create();
100
5
        if (data_type->is_nullable()) {
101
0
            return doris::ColumnNullable::create(std::move(ptr), doris::ColumnUInt8::create());
102
0
        }
103
5
        return ptr;
104
5
    }
105
481
    return data_type->create_column();
106
486
}
107
108
} // namespace doris