Coverage Report

Created: 2026-07-05 00:16

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