Coverage Report

Created: 2026-03-14 18:33

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
be/src/storage/segment/parsed_page.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 <memory>
23
24
#include "common/status.h"
25
#include "storage/segment/binary_dict_page.h"
26
#include "storage/segment/common.h"
27
#include "storage/segment/encoding_info.h"
28
#include "storage/segment/options.h"
29
#include "storage/segment/page_decoder.h"
30
#include "storage/segment/page_handle.h"
31
#include "util/rle_encoding.h"
32
33
namespace doris {
34
namespace segment_v2 {
35
36
// This contains information when one page is loaded, and ready for read
37
// This struct can be reused, client should call reset first before reusing
38
// this object
39
struct ParsedPage {
40
    static Status create(PageHandle handle, const Slice& body, const DataPageFooterPB& footer,
41
                         const EncodingInfo* encoding, const PagePointer& page_pointer,
42
                         uint32_t page_index, ParsedPage* result,
43
5.93M
                         PageDecoderOptions opts = PageDecoderOptions()) {
44
5.93M
        result->~ParsedPage();
45
5.93M
        ParsedPage* page = new (result)(ParsedPage);
46
5.93M
        page->page_handle = std::move(handle);
47
48
5.93M
        auto null_size = footer.nullmap_size();
49
5.93M
        page->has_null = null_size > 0;
50
5.93M
        page->null_bitmap = Slice(body.data + body.size - null_size, null_size);
51
52
5.93M
        if (page->has_null) {
53
350k
            page->null_decoder =
54
350k
                    RleDecoder<bool>((const uint8_t*)page->null_bitmap.data, null_size, 1);
55
350k
        }
56
57
5.93M
        Slice data_slice(body.data, body.size - null_size);
58
5.93M
        PageDecoder* decoder;
59
5.93M
        RETURN_IF_ERROR(encoding->create_page_decoder(data_slice, opts, &decoder));
60
5.93M
        page->data_decoder.reset(decoder);
61
5.93M
        RETURN_IF_ERROR(page->data_decoder->init());
62
63
5.93M
        if (encoding->encoding() == DICT_ENCODING) {
64
515k
            auto dict_decoder = static_cast<BinaryDictPageDecoder*>(page->data_decoder.get());
65
515k
            page->is_dict_encoding = dict_decoder->is_dict_encoding();
66
515k
        }
67
68
5.93M
        page->first_ordinal = footer.first_ordinal();
69
5.93M
        page->num_rows = footer.num_values();
70
71
5.93M
        page->page_pointer = page_pointer;
72
5.93M
        page->page_index = page_index;
73
74
5.93M
        page->next_array_item_ordinal = footer.next_array_item_ordinal();
75
76
5.93M
        return Status::OK();
77
5.93M
    }
78
79
29.6M
    ~ParsedPage() { data_decoder = nullptr; }
80
81
    PageHandle page_handle;
82
83
    bool has_null;
84
    Slice null_bitmap;
85
    RleDecoder<bool> null_decoder;
86
    std::unique_ptr<PageDecoder> data_decoder;
87
88
    // ordinal of the first value in this page
89
    ordinal_t first_ordinal = 0;
90
    // number of rows including nulls and not-nulls
91
    ordinal_t num_rows = 0;
92
    // record it to get the last array element's size
93
    // should be none zero if set in page
94
    ordinal_t next_array_item_ordinal = 0;
95
96
    PagePointer page_pointer;
97
    uint32_t page_index = 0;
98
99
    // current offset when read this page
100
    // this means next row we will read
101
    ordinal_t offset_in_page = 0;
102
103
    bool is_dict_encoding = false;
104
105
6.51M
    bool contains(ordinal_t ord) {
106
6.51M
        return ord >= first_ordinal && ord < (first_ordinal + num_rows);
107
6.51M
    }
108
109
8.12M
    operator bool() const { return data_decoder != nullptr; }
110
111
7.59M
    bool has_remaining() const { return offset_in_page < num_rows; }
112
113
10.7M
    size_t remaining() const { return num_rows - offset_in_page; }
114
};
115
116
} // namespace segment_v2
117
} // namespace doris