diff --git a/parquet/src/file/page_index/index.rs b/parquet/src/file/page_index/index.rs index ab342d52b7f5..71fb47afa960 100644 --- a/parquet/src/file/page_index/index.rs +++ b/parquet/src/file/page_index/index.rs @@ -19,7 +19,7 @@ use crate::basic::Type; use crate::data_type::private::ParquetValueType; -use crate::data_type::{ByteArray, FixedLenByteArray, Int96}; +use crate::data_type::{AsBytes, ByteArray, FixedLenByteArray, Int96}; use crate::errors::ParquetError; use crate::format::{BoundaryOrder, ColumnIndex}; use crate::util::bit_util::from_le_slice; @@ -55,6 +55,19 @@ impl PageIndex { } } +impl PageIndex +where + T: AsBytes, +{ + pub fn max_bytes(&self) -> Option<&[u8]> { + self.max.as_ref().map(|x| x.as_bytes()) + } + + pub fn min_bytes(&self) -> Option<&[u8]> { + self.min.as_ref().map(|x| x.as_bytes()) + } +} + #[derive(Debug, Clone, PartialEq)] #[allow(non_camel_case_types)] /// Typed statistics for a data page in a column chunk. @@ -156,3 +169,38 @@ impl NativeIndex { }) } } + +#[cfg(test)] +mod tests { + use super::*; + + #[test] + fn test_page_index_min_max_null() { + let page_index = PageIndex { + min: Some(-123), + max: Some(234), + null_count: Some(0), + }; + + assert_eq!(page_index.min().unwrap(), &-123); + assert_eq!(page_index.max().unwrap(), &234); + assert_eq!(page_index.min_bytes().unwrap(), (-123).as_bytes()); + assert_eq!(page_index.max_bytes().unwrap(), 234.as_bytes()); + assert_eq!(page_index.null_count().unwrap(), 0); + } + + #[test] + fn test_page_index_min_max_null_none() { + let page_index: PageIndex = PageIndex { + min: None, + max: None, + null_count: None, + }; + + assert_eq!(page_index.min(), None); + assert_eq!(page_index.max(), None); + assert_eq!(page_index.min_bytes(), None); + assert_eq!(page_index.max_bytes(), None); + assert_eq!(page_index.null_count(), None); + } +}