-
Notifications
You must be signed in to change notification settings - Fork 1k
Add ability to skip or transform page encoding statistics in Parquet metadata #8797
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
etseidl
wants to merge
4
commits into
apache:main
Choose a base branch
from
etseidl:page_enc_stats
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -813,6 +813,7 @@ pub struct ColumnChunkMetaData { | |
| statistics: Option<Statistics>, | ||
| geo_statistics: Option<Box<geo_statistics::GeospatialStatistics>>, | ||
| encoding_stats: Option<Vec<PageEncodingStats>>, | ||
| encoding_stats_mask: Option<EncodingMask>, | ||
| bloom_filter_offset: Option<i64>, | ||
| bloom_filter_length: Option<i32>, | ||
| offset_index_offset: Option<i64>, | ||
|
|
@@ -1050,12 +1051,43 @@ impl ColumnChunkMetaData { | |
| self.geo_statistics.as_deref() | ||
| } | ||
|
|
||
| /// Returns the offset for the page encoding stats, | ||
| /// or `None` if no page encoding stats are available. | ||
| /// Returns the page encoding statistics, or `None` if no page encoding statistics | ||
| /// are available. | ||
| pub fn page_encoding_stats(&self) -> Option<&Vec<PageEncodingStats>> { | ||
| self.encoding_stats.as_ref() | ||
| } | ||
|
|
||
| /// Returns the page encoding statistics reduced to a bitmask, or `None` if statistics are | ||
| /// not available. | ||
| /// | ||
| /// The [`PageEncodingStats`] struct was added to the Parquet specification specifically to | ||
| /// enable fast determination of whether all pages in a column chunk are dictionary encoded | ||
| /// (see <https://github.com/apache/parquet-format/pull/16>). | ||
| /// Decoding the full page encoding statistics, however, can be very costly, and is not | ||
| /// necessary to support the aforementioned use case. As an alternative, this crate can | ||
| /// instead distill the list of `PageEncodingStats` down to a bitmask of just the encodings | ||
| /// used for data pages | ||
| /// (see [`ParquetMetaDataOptions::set_encoding_stats_as_mask`]). | ||
| /// To test for an all-dictionary-encoded chunk one could use this bitmask in the following way: | ||
| /// | ||
| /// ```rust | ||
| /// use parquet::basic::Encoding; | ||
| /// use parquet::file::metadata::ColumnChunkMetaData; | ||
| /// // test if all data pages in the column chunk are dictionary encoded | ||
| /// fn is_all_dictionary_encoded(col_meta: &ColumnChunkMetaData) -> bool { | ||
| /// // check that dictionary encoding was used | ||
| /// col_meta.dictionary_page_offset().is_some() | ||
| /// && col_meta.page_encoding_stats_mask().is_some_and(|mask| { | ||
| /// // mask should only have one bit set, either for PLAIN_DICTIONARY or | ||
| /// // RLE_DICTIONARY | ||
| /// mask.is_only(Encoding::PLAIN_DICTIONARY) || mask.is_only(Encoding::RLE_DICTIONARY) | ||
| /// }) | ||
| /// } | ||
| /// ``` | ||
| pub fn page_encoding_stats_mask(&self) -> Option<&EncodingMask> { | ||
| self.encoding_stats_mask.as_ref() | ||
| } | ||
|
|
||
| /// Returns the offset for the bloom filter. | ||
| pub fn bloom_filter_offset(&self) -> Option<i64> { | ||
| self.bloom_filter_offset | ||
|
|
@@ -1178,6 +1210,7 @@ impl ColumnChunkMetaDataBuilder { | |
| statistics: None, | ||
| geo_statistics: None, | ||
| encoding_stats: None, | ||
| encoding_stats_mask: None, | ||
| bloom_filter_offset: None, | ||
| bloom_filter_length: None, | ||
| offset_index_offset: None, | ||
|
|
@@ -1278,6 +1311,12 @@ impl ColumnChunkMetaDataBuilder { | |
| self | ||
| } | ||
|
|
||
| /// Sets page encoding stats mask for this column chunk. | ||
| pub fn set_page_encoding_stats_mask(mut self, value: EncodingMask) -> Self { | ||
| self.0.encoding_stats_mask = Some(value); | ||
| self | ||
| } | ||
|
|
||
| /// Clears the page encoding stats for this column chunk. | ||
| pub fn clear_page_encoding_stats(mut self) -> Self { | ||
| self.0.encoding_stats = None; | ||
|
|
@@ -1882,9 +1921,9 @@ mod tests { | |
| .build(); | ||
|
|
||
| #[cfg(not(feature = "encryption"))] | ||
| let base_expected_size = 2766; | ||
| let base_expected_size = 2798; | ||
| #[cfg(feature = "encryption")] | ||
| let base_expected_size = 2934; | ||
| let base_expected_size = 2966; | ||
|
|
||
| assert_eq!(parquet_meta.memory_size(), base_expected_size); | ||
|
|
||
|
|
@@ -1913,9 +1952,9 @@ mod tests { | |
| .build(); | ||
|
|
||
| #[cfg(not(feature = "encryption"))] | ||
| let bigger_expected_size = 3192; | ||
| let bigger_expected_size = 3224; | ||
| #[cfg(feature = "encryption")] | ||
| let bigger_expected_size = 3360; | ||
| let bigger_expected_size = 3392; | ||
|
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This is for adding the mask to |
||
|
|
||
| // more set fields means more memory usage | ||
| assert!(bigger_expected_size > base_expected_size); | ||
|
|
@@ -1962,7 +2001,7 @@ mod tests { | |
| .set_row_groups(row_group_meta.clone()) | ||
| .build(); | ||
|
|
||
| let base_expected_size = 2058; | ||
| let base_expected_size = 2074; | ||
| assert_eq!(parquet_meta_data.memory_size(), base_expected_size); | ||
|
|
||
| let footer_key = "0123456789012345".as_bytes(); | ||
|
|
@@ -1988,7 +2027,7 @@ mod tests { | |
| .set_file_decryptor(Some(decryptor)) | ||
| .build(); | ||
|
|
||
| let expected_size_with_decryptor = 3072; | ||
| let expected_size_with_decryptor = 3088; | ||
| assert!(expected_size_with_decryptor > base_expected_size); | ||
|
|
||
| assert_eq!( | ||
|
|
||
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I wonder if this should be
data_page_encoding_stats_mask(or justdata_page_encoding_stats) to make it clear it only has the stats for data pages.