Coverage Report

Created: 2026-03-16 17:53

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
#include "common/compile_check_begin.h"
29
30
struct VariantStatistics {
31
    std::map<std::string, int64_t> subcolumns_non_null_size;
32
    std::map<std::string, uint32_t> sparse_column_non_null_size;
33
    std::map<std::string, uint32_t> doc_value_column_non_null_size;
34
    bool has_nested_group = false;
35
36
635
    void to_pb(VariantStatisticsPB* stats) const {
37
635
        if (stats == nullptr) {
38
0
            return;
39
0
        }
40
635
        stats->Clear();
41
635
        auto* sparse_map = stats->mutable_sparse_column_non_null_size();
42
4.15k
        for (const auto& [path, value] : sparse_column_non_null_size) {
43
4.15k
            (*sparse_map)[path] = value;
44
4.15k
        }
45
635
        auto* doc_value_map = stats->mutable_doc_value_column_non_null_size();
46
635
        for (const auto& [path, value] : doc_value_column_non_null_size) {
47
31
            (*doc_value_map)[path] = value;
48
31
        }
49
635
        stats->set_has_nested_group(has_nested_group);
50
635
    }
51
52
    // Additive merge: only update sparse_column_non_null_size from pb
53
    // without touching other maps (subcolumns, doc_value, has_nested_group).
54
380
    void merge_sparse_from_pb(const VariantStatisticsPB& stats) {
55
2.50k
        for (const auto& [path, value] : stats.sparse_column_non_null_size()) {
56
2.50k
            sparse_column_non_null_size[path] += value;
57
2.50k
        }
58
380
    }
59
60
    // Additive merge: only update doc_value_column_non_null_size from pb
61
    // without touching other maps.
62
10
    void merge_doc_value_from_pb(const VariantStatisticsPB& stats) {
63
35
        for (const auto& [path, value] : stats.doc_value_column_non_null_size()) {
64
35
            doc_value_column_non_null_size[path] += value;
65
35
        }
66
10
    }
67
68
0
    bool has_sparse_column_non_null_size() const { return !sparse_column_non_null_size.empty(); }
69
211
    bool has_doc_value_column_non_null_size() const {
70
211
        return !doc_value_column_non_null_size.empty();
71
211
    }
72
73
238
    bool existed_in_sparse_column(const std::string& relative_path) const {
74
238
        return sparse_column_non_null_size.contains(relative_path);
75
238
    }
76
77
6
    bool existed_in_doc_value_column(const std::string& relative_path) const {
78
6
        return doc_value_column_non_null_size.contains(relative_path);
79
6
    }
80
81
22
    bool has_prefix_path_in_sparse_column(const std::string& dot_prefix) const {
82
22
        auto it = sparse_column_non_null_size.lower_bound(dot_prefix);
83
22
        return it != sparse_column_non_null_size.end() && it->first.starts_with(dot_prefix);
84
22
    }
85
86
6
    bool has_prefix_path_in_doc_value_column(const std::string& dot_prefix) const {
87
6
        auto it = doc_value_column_non_null_size.lower_bound(dot_prefix);
88
6
        return it != doc_value_column_non_null_size.end() && it->first.starts_with(dot_prefix);
89
6
    }
90
91
1
    bool has_doc_column_non_null_size() const { return has_doc_value_column_non_null_size(); }
92
0
    bool existed_in_doc_column(const std::string& relative_path) const {
93
0
        return existed_in_doc_value_column(relative_path);
94
0
    }
95
0
    bool has_prefix_path_in_doc_column(const std::string& dot_prefix) const {
96
0
        return has_prefix_path_in_doc_value_column(dot_prefix);
97
0
    }
98
};
99
#include "common/compile_check_end.h"
100
101
} // namespace doris::segment_v2