Coverage Report

Created: 2026-04-11 00:05

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/segment/variant/variant_statistics.h
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
#pragma once
19
20
#include <gen_cpp/segment_v2.pb.h>
21
22
#include <cstdint>
23
#include <map>
24
#include <string>
25
26
namespace doris::segment_v2 {
27
28
struct VariantStatistics {
29
    std::map<std::string, int64_t> subcolumns_non_null_size;
30
    std::map<std::string, uint32_t> sparse_column_non_null_size;
31
    std::map<std::string, uint32_t> doc_value_column_non_null_size;
32
    bool has_nested_group = false;
33
34
637
    void to_pb(VariantStatisticsPB* stats) const {
35
637
        if (stats == nullptr) {
36
0
            return;
37
0
        }
38
637
        stats->Clear();
39
637
        auto* sparse_map = stats->mutable_sparse_column_non_null_size();
40
4.15k
        for (const auto& [path, value] : sparse_column_non_null_size) {
41
4.15k
            (*sparse_map)[path] = value;
42
4.15k
        }
43
637
        auto* doc_value_map = stats->mutable_doc_value_column_non_null_size();
44
637
        for (const auto& [path, value] : doc_value_column_non_null_size) {
45
31
            (*doc_value_map)[path] = value;
46
31
        }
47
637
        stats->set_has_nested_group(has_nested_group);
48
637
    }
49
50
    // Additive merge: only update sparse_column_non_null_size from pb
51
    // without touching other maps (subcolumns, doc_value, has_nested_group).
52
374
    void merge_sparse_from_pb(const VariantStatisticsPB& stats) {
53
2.50k
        for (const auto& [path, value] : stats.sparse_column_non_null_size()) {
54
2.50k
            sparse_column_non_null_size[path] += value;
55
2.50k
        }
56
374
    }
57
58
    // Additive merge: only update doc_value_column_non_null_size from pb
59
    // without touching other maps.
60
11
    void merge_doc_value_from_pb(const VariantStatisticsPB& stats) {
61
39
        for (const auto& [path, value] : stats.doc_value_column_non_null_size()) {
62
39
            doc_value_column_non_null_size[path] += value;
63
39
        }
64
11
    }
65
66
0
    bool has_sparse_column_non_null_size() const { return !sparse_column_non_null_size.empty(); }
67
212
    bool has_doc_value_column_non_null_size() const {
68
212
        return !doc_value_column_non_null_size.empty();
69
212
    }
70
71
239
    bool existed_in_sparse_column(const std::string& relative_path) const {
72
239
        return sparse_column_non_null_size.contains(relative_path);
73
239
    }
74
75
6
    bool existed_in_doc_value_column(const std::string& relative_path) const {
76
6
        return doc_value_column_non_null_size.contains(relative_path);
77
6
    }
78
79
22
    bool has_prefix_path_in_sparse_column(const std::string& dot_prefix) const {
80
22
        auto it = sparse_column_non_null_size.lower_bound(dot_prefix);
81
22
        return it != sparse_column_non_null_size.end() && it->first.starts_with(dot_prefix);
82
22
    }
83
84
6
    bool has_prefix_path_in_doc_value_column(const std::string& dot_prefix) const {
85
6
        auto it = doc_value_column_non_null_size.lower_bound(dot_prefix);
86
6
        return it != doc_value_column_non_null_size.end() && it->first.starts_with(dot_prefix);
87
6
    }
88
89
1
    bool has_doc_column_non_null_size() const { return has_doc_value_column_non_null_size(); }
90
0
    bool existed_in_doc_column(const std::string& relative_path) const {
91
0
        return existed_in_doc_value_column(relative_path);
92
0
    }
93
0
    bool has_prefix_path_in_doc_column(const std::string& dot_prefix) const {
94
0
        return has_prefix_path_in_doc_value_column(dot_prefix);
95
0
    }
96
};
97
98
} // namespace doris::segment_v2