pub fn decode_offset_index(
data: &[u8],
) -> Result<OffsetIndexMetaData, ParquetError>Expand description
Decode a Thrift OffsetIndex from the provided bytes.
The passed in bytes contain a serialized Thrift OffsetIndex struct as
read from a Parquet file.
Returns an OffsetIndexMetaData containing page location information.
ยงExample
// Open the Parquet file
let mut file = File::open("data.parquet")?;
let reader = SerializedFileReader::new(file.try_clone()?)?;
let metadata = reader.metadata();
// Select a row group and column to read
let row_group_idx = 0;
let column_idx = 0;
// Get the column chunk metadata
let row_group = metadata.row_group(row_group_idx);
let column_chunk = row_group.column(column_idx);
// Get the offset index byte range from the column metadata
if let Some(range) = column_chunk.offset_index_range() {
// Read the offset index bytes from the file
let mut buffer = vec![0u8; (range.end - range.start) as usize];
file.seek(std::io::SeekFrom::Start(range.start))?;
file.read_exact(&mut buffer)?;
// Decode the offset index
let offset_index = decode_offset_index(&buffer)?;
// Access page location information
for (i, page_location) in offset_index.page_locations().iter().enumerate() {
println!("Page {}: offset={}, size={}, first_row={}",
i,
page_location.offset,
page_location.compressed_page_size,
page_location.first_row_index
);
}
}