Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 8 additions & 13 deletions parquet/src/file/metadata/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,12 @@
//! These functions parse thrift-encoded metadata from a byte slice
//! into the corresponding Rust structures

use std::{ops::Range, sync::Arc};
use std::ops::Range;

use bytes::Bytes;

use crate::errors::{ParquetError, Result};
use crate::file::metadata::page_index::{PageIndexBuilder, PageIndexProvider};
use crate::file::metadata::page_index::{PageIndex, PageIndexBuilder, PageIndexProvider};
use crate::file::metadata::thrift::parquet_metadata_from_bytes;
use crate::file::metadata::{
ColumnChunkMask, ColumnChunkMetaData, PageIndexPolicy, ParquetMetaData, ParquetMetaDataOptions,
Expand Down Expand Up @@ -235,10 +235,10 @@ pub(crate) fn decode_metadata(
parquet_metadata_from_bytes(buf, options)
}

/// Parses page indexes from the provided bytes and replaces those in the metadata.
/// Parses page indexes from the provided bytes.
///
/// Arguments
/// * `metadata` - The ParquetMetaData whose page index will be replaced.
/// * `metadata` - The footer metadata describing the page index locations.
/// * `column_index_policy` - The policy for handling column index parsing (e.g.,
/// Required, Optional, Skip).
/// * `offset_index_policy` - The policy for handling offset index parsing (e.g.,
Expand All @@ -250,14 +250,14 @@ pub(crate) fn decode_metadata(
/// * `bytes` - The byte slice containing the page index data.
/// * `start_offset` - The offset where `bytes` begin in the file.
pub(crate) fn parse_page_index(
metadata: &mut ParquetMetaData,
metadata: &ParquetMetaData,
column_index_policy: PageIndexPolicy,
offset_index_policy: PageIndexPolicy,
column_index_mask: &ColumnChunkMask,
offset_index_mask: &ColumnChunkMask,
bytes: &Bytes,
start_offset: u64,
) -> Result<()> {
) -> Result<Option<PageIndex>> {
let num_row_groups = metadata.num_row_groups();
let num_columns = metadata.file_metadata().schema_descr().num_columns();
let mut builder = PageIndexBuilder::default();
Expand Down Expand Up @@ -285,17 +285,12 @@ pub(crate) fn parse_page_index(
)?;
}

// Always replace the page index, even if both policies are Skip.
// This ensures that repeated calls to read_page_indexes replace the existing index
// rather than preserving it.
let page_index = builder.build();
if page_index.has_column_indexes() || page_index.has_offset_indexes() {
metadata.set_page_index(Some(Arc::new(page_index)));
Ok(Some(page_index))

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this is a much nicer API 👍

} else {
// If no indexes were read, clear the page index
metadata.set_page_index(None);
Ok(None)
}
Ok(())
}

fn parse_column_index(
Expand Down
Loading
Loading