You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by tu...@apache.org on 2024/06/26 10:10:04 UTC

(arrow-rs) branch master updated: feat: add max_bytes and min_bytes on PageIndex (#5950)

This is an automated email from the ASF dual-hosted git repository.

tustvold pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/master by this push:
     new 45190ab5289 feat: add max_bytes and min_bytes on PageIndex (#5950)
45190ab5289 is described below

commit 45190ab528927bb3e5213427910ab1bcaa943dc6
Author: Trent Hauck <tr...@trenthauck.com>
AuthorDate: Wed Jun 26 03:09:59 2024 -0700

    feat: add max_bytes and min_bytes on PageIndex (#5950)
---
 parquet/src/file/page_index/index.rs | 50 +++++++++++++++++++++++++++++++++++-
 1 file changed, 49 insertions(+), 1 deletion(-)

diff --git a/parquet/src/file/page_index/index.rs b/parquet/src/file/page_index/index.rs
index ab342d52b7f..71fb47afa96 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<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.
@@ -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);
+    }
+}