Skip to content
Merged
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
50 changes: 49 additions & 1 deletion parquet/src/file/page_index/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -55,6 +55,19 @@ impl<T> PageIndex<T> {
}
}

impl<T> PageIndex<T>
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.
Expand Down Expand Up @@ -156,3 +169,38 @@ impl<T: ParquetValueType> NativeIndex<T> {
})
}
}

#[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<i32> = 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);
}
}