parquet/file/page_index/
offset_index.rs

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//! [`OffsetIndexMetaData`] structure holding decoded [`OffsetIndex`] information
19
20use crate::errors::ParquetError;
21use crate::format::{OffsetIndex, PageLocation};
22
23/// [`OffsetIndex`] information for a column chunk. Contains offsets and sizes for each page
24/// in the chunk. Optionally stores fully decoded page sizes for BYTE_ARRAY columns.
25#[derive(Debug, Clone, PartialEq)]
26pub struct OffsetIndexMetaData {
27    /// Vector of [`PageLocation`] objects, one per page in the chunk.
28    pub page_locations: Vec<PageLocation>,
29    /// Optional vector of unencoded page sizes, one per page in the chunk.
30    /// Only defined for BYTE_ARRAY columns.
31    pub unencoded_byte_array_data_bytes: Option<Vec<i64>>,
32}
33
34impl OffsetIndexMetaData {
35    /// Creates a new [`OffsetIndexMetaData`] from an [`OffsetIndex`].
36    pub(crate) fn try_new(index: OffsetIndex) -> Result<Self, ParquetError> {
37        Ok(Self {
38            page_locations: index.page_locations,
39            unencoded_byte_array_data_bytes: index.unencoded_byte_array_data_bytes,
40        })
41    }
42
43    /// Vector of [`PageLocation`] objects, one per page in the chunk.
44    pub fn page_locations(&self) -> &Vec<PageLocation> {
45        &self.page_locations
46    }
47
48    /// Optional vector of unencoded page sizes, one per page in the chunk. Only defined
49    /// for BYTE_ARRAY columns.
50    pub fn unencoded_byte_array_data_bytes(&self) -> Option<&Vec<i64>> {
51        self.unencoded_byte_array_data_bytes.as_ref()
52    }
53
54    // TODO: remove annotation after merge
55    #[allow(dead_code)]
56    pub(crate) fn to_thrift(&self) -> OffsetIndex {
57        OffsetIndex::new(
58            self.page_locations.clone(),
59            self.unencoded_byte_array_data_bytes.clone(),
60        )
61    }
62}