pub struct PageIndex {
column_indexes: Option<Vec<Vec<Option<ColumnIndexMetaData>>>>,
offset_indexes: Option<Vec<Vec<Option<OffsetIndexMetaData>>>>,
}Expand description
Encapsulates the Parquet Page Index for efficient page-level data skipping
The Page Index is optional metadata that enables query engines to skip irrelevant data pages during scans, significantly improving I/O efficiency. It consists of two complementary structures:
-
ColumnIndex: Per-page min/max value boundaries that enable predicate-based page filtering. Allows determining which pages might contain rows matching a query predicate without reading the actual data pages. -
OffsetIndex: Physical locations and sizes of data pages, plus the first row index of each page. Used to locate and read only the pages identified as relevant by the ColumnIndex.
Together, these indexes enable:
- Single-row lookups reading only one data page per column (on sorted columns)
- Range scans reading only pages containing values in the query range
- Efficient cross-column filtering by skipping corresponding row ranges
§Structure
Within a Parquet file, both indexes are organized as a two-level structure, with
indexes arranged first by row group, and then column. The ColumnChunkMetaData
contains pointers to the indexes for a given column chunk, so they may be
populated piecemeal. This struct allows access either by row group index
(Self::column_indexes_for_rowgroup, Self::offset_indexes_for_rowgroup) or
individual access by row group index and column number (Self::column_index,
Self::offset_index).
Each entry is Option<T> because:
- The entire page index might be absent (old files, disabled during write)
- Individual columns might lack indexes (unsupported types, statistics disabled)
§Example: Checking if Page Index is Available
use parquet::file::metadata::ParquetMetaData;
fn check_page_index_availability(metadata: &ParquetMetaData) -> Result<()> {
if let Some(page_index) = metadata.page_index() {
println!("Page index present:");
println!(" Has offset indexes: {}", page_index.has_offset_indexes());
println!(" Has column indexes: {}", page_index.has_column_indexes());
// Check availability for first row group, first column
if let Some(col_idx) = page_index.column_index(0, 0) {
println!(" Column index found for row group 0, column 0");
println!(" Number of pages: {}", col_idx.num_pages());
}
if let Some(offset_idx) = page_index.offset_index(0, 0) {
println!(" Offset index found for row group 0, column 0");
println!(" Number of pages: {}", offset_idx.page_locations().len());
}
} else {
println!("No page index available");
}
Ok(())
}§Example: Using Page Index for Predicate Pushdown
use parquet::file::metadata::ParquetMetaData;
use parquet::file::page_index::column_index::ColumnIndexMetaData;
/// Identifies which pages in a column might contain values >= min_value
fn find_relevant_pages(
metadata: &ParquetMetaData,
row_group_idx: usize,
column_idx: usize,
min_value: i32,
) -> Vec<usize> {
let mut relevant_pages = Vec::new();
let Some(page_index) = metadata.page_index() else {
// No page index - must read all pages
return relevant_pages;
};
let Some(column_index) = page_index.column_index(row_group_idx, column_idx) else {
// No column index - must read all pages
return relevant_pages;
};
// Check each page's statistics
match column_index {
ColumnIndexMetaData::INT32(index) => {
for (page_num, max_value) in index.max_values_iter().enumerate() {
// Page might contain matching rows if its max >= our min
if let Some(max) = max_value {
if *max >= min_value {
relevant_pages.push(page_num);
}
}
}
}
_ => {
// Wrong column type - read all pages
}
}
relevant_pages
}Fields§
§column_indexes: Option<Vec<Vec<Option<ColumnIndexMetaData>>>>§offset_indexes: Option<Vec<Vec<Option<OffsetIndexMetaData>>>>Implementations§
Source§impl PageIndex
impl PageIndex
pub(crate) fn new( column_indexes: Option<Vec<Vec<Option<ColumnIndexMetaData>>>>, offset_indexes: Option<Vec<Vec<Option<OffsetIndexMetaData>>>>, ) -> Self
Sourcepub fn has_offset_indexes(&self) -> bool
pub fn has_offset_indexes(&self) -> bool
Returns true if offset index structures are present
This indicates whether OffsetIndexMetaData structures were loaded or created.
Returns true even if some individual columns lack offset indexes.
To check if a specific column has an offset index, use Self::offset_index.
Sourcepub fn has_column_indexes(&self) -> bool
pub fn has_column_indexes(&self) -> bool
Returns true if column index structures are present
This indicates whether ColumnIndexMetaData structures were loaded or created.
Returns true even if some individual columns lack column indexes.
To check if a specific column has a column index, use Self::column_index.
Sourcepub fn is_complete(&self) -> bool
pub fn is_complete(&self) -> bool
Returns true if both the offset and column index structures are present
This is equivalent to both Self::has_offset_indexes and Self::has_column_indexes
returning true.
Sourcepub fn column_indexes_for_rowgroup(
&self,
row_group_idx: usize,
) -> Option<&[Option<ColumnIndexMetaData>]>
pub fn column_indexes_for_rowgroup( &self, row_group_idx: usize, ) -> Option<&[Option<ColumnIndexMetaData>]>
Returns column indexes for all columns in the specified row group
Returns None if:
- Column indexes were not loaded or are not available
- The row group index is out of bounds
Returns Some(&[Option<ColumnIndexMetaData>]) where:
- The slice length equals the number of columns in the row group
- Each element is
Someif that column has statistics,Noneotherwise
Sourcepub fn column_index(
&self,
row_group_idx: usize,
column_idx: usize,
) -> Option<&ColumnIndexMetaData>
pub fn column_index( &self, row_group_idx: usize, column_idx: usize, ) -> Option<&ColumnIndexMetaData>
Returns the column index for a specific row group and column
This is the primary method for accessing page-level min/max statistics used in predicate pushdown and page skipping optimizations.
Returns:
Some(&ColumnIndexMetaData)- Column index is available with statisticsNone- Index unavailable (not loaded, row group/column out of bounds, or no statistics)
Sourcepub fn offset_indexes_for_rowgroup(
&self,
row_group_idx: usize,
) -> Option<&[Option<OffsetIndexMetaData>]>
pub fn offset_indexes_for_rowgroup( &self, row_group_idx: usize, ) -> Option<&[Option<OffsetIndexMetaData>]>
Returns offset indexes for all columns in the specified row group
Returns None if:
- Offset indexes were not loaded or are not available
- The row group index is out of bounds
Returns Some(&[Option<OffsetIndexMetaData>]) where:
- The slice length equals the number of columns in the row group
- Each element is
Someif that column has location metadata,Noneotherwise
Sourcepub fn offset_index(
&self,
row_group_idx: usize,
column_idx: usize,
) -> Option<&OffsetIndexMetaData>
pub fn offset_index( &self, row_group_idx: usize, column_idx: usize, ) -> Option<&OffsetIndexMetaData>
Returns the offset index for a specific row group and column
This provides physical locations and sizes of data pages, enabling:
- Direct seeking to specific pages identified by column index filtering
- Reading only relevant pages without scanning entire column chunks
- Efficient cross-column row-based filtering
Returns:
Some(&OffsetIndexMetaData)- Offset index is availableNone- Index unavailable (not loaded, row group/column out of bounds)
Sourcepub fn num_data_pages(
&self,
row_group_idx: usize,
column_idx: usize,
) -> Option<usize>
pub fn num_data_pages( &self, row_group_idx: usize, column_idx: usize, ) -> Option<usize>
Returns the expected number of data pages for a specific column chunk
This count includes only data pages, not dictionary pages or other metadata pages.
Returns:
Some(usize)- Number of data pages if any index is availableNone- No index information available for this column
Sourcepub fn page_locations(
&self,
row_group_idx: usize,
column_idx: usize,
) -> Option<&Vec<PageLocation>>
pub fn page_locations( &self, row_group_idx: usize, column_idx: usize, ) -> Option<&Vec<PageLocation>>
Returns the physical locations of all data pages in a column chunk
Each PageLocation contains:
- File offset where the page begins
- Compressed size of the page
- First row index within the row group
This enables direct I/O to specific pages without reading the entire column chunk.
Returns:
Some(&Vec<PageLocation>)- Vector of page locations if offset index existsNone- Offset index not available