Skip to content

Commit

Permalink
feat: add max_bytes and min_bytes on PageIndex (#5950)
Browse files Browse the repository at this point in the history
  • Loading branch information
tshauck authored Jun 26, 2024
1 parent 4b326f6 commit 45190ab
Showing 1 changed file with 49 additions and 1 deletion.
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);
}
}

0 comments on commit 45190ab

Please sign in to comment.