Coverage Report

Created: 2026-06-16 22:19

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_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
6.59k
                   size_t num_key_columns) {
74
6.59k
    _col_ids = col_ids;
75
6.59k
    _num_key_columns = num_key_columns;
76
77
6.59k
    _cols.resize(cols.size());
78
79
6.59k
    std::unordered_set<uint32_t> col_id_set(col_ids.begin(), col_ids.end());
80
66.7k
    for (int cid = 0; cid < cols.size(); ++cid) {
81
60.1k
        if (col_id_set.find(cid) == col_id_set.end()) {
82
41.5k
            continue;
83
41.5k
        }
84
18.5k
        _cols[cid] = cols[cid];
85
18.5k
    }
86
6.59k
}
87
88
6.59k
Schema::~Schema() = default;
89
90
66.7k
DataTypePtr Schema::get_data_type_ptr(const TabletColumn& column) {
91
66.7k
    return DataTypeFactory::instance().create_data_type(column);
92
66.7k
}
93
94
IColumn::MutablePtr Schema::get_predicate_column_ptr(const DataTypePtr& data_type,
95
467
                                                     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
467
    if (config::enable_low_cardinality_optimize && reader_type == ReaderType::READER_QUERY &&
100
467
        is_string_type(data_type->get_primitive_type())) {
101
0
        IColumn::MutablePtr ptr = doris::ColumnDictI32::create();
102
0
        if (data_type->is_nullable()) {
103
0
            return doris::ColumnNullable::create(std::move(ptr), doris::ColumnUInt8::create());
104
0
        }
105
0
        return ptr;
106
0
    }
107
467
    return data_type->create_column();
108
467
}
109
110
} // namespace doris