pub fn decode_column_index(
data: &[u8],
column_type: Type,
) -> Result<ColumnIndexMetaData, ParquetError>Expand description
Decode a Thrift ColumnIndex from the provided bytes.
The passed in bytes contain a serialized Thrift OffsetIndex struct as
read from a Parquet file. The column_type can be obtained via
ColumnChunkMetaData::column_type.
Returns a ColumnIndexMetaData containing per-page statistics.
ยง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 column index byte range from the column metadata
if let Some(range) = column_chunk.column_index_range() {
// Get the column type for proper deserialization
let column_type = column_chunk.column_type();
// Read the column 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 column index
let column_index = decode_column_index(&buffer, column_type)?;
// Access per-page statistics (example for INT32 column)
use parquet::file::page_index::column_index::ColumnIndexMetaData;
match column_index {
ColumnIndexMetaData::INT32(index) => {
for (i, (min, max)) in index.min_values().iter()
.zip(index.max_values().iter())
.enumerate() {
println!("Page {}: min={}, max={}", i, min, max);
}
}
_ => println!("Column is not INT32 type"),
}
}