Repository navigation
feat(parquet): allow updating cached file key-value metadata #12117
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
Merged
Merged
Changes from all commits
Commits
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -393,6 +393,18 @@ impl ParquetMetaDataBuilder { | |
| } | ||
| } | ||
|
|
||
| /// Replaces the file-level key-value metadata. | ||
| /// | ||
| /// Pass `None` to remove all entries. This only updates the in-memory metadata; | ||
| /// it does not modify the Parquet file. | ||
| /// | ||
| /// Other metadata, including row groups, page indexes, and decryption state, | ||
| /// is preserved. Shared file metadata is cloned before modification. | ||
|
Contributor
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. technically speaking I think the shared file metadata is "cloned if necessary" (if there there are no other copied it won't be cloned) |
||
| pub fn set_key_value_metadata(mut self, key_value_metadata: Option<Vec<KeyValue>>) -> Self { | ||
| Arc::make_mut(&mut self.file_metadata).key_value_metadata = key_value_metadata; | ||
| self | ||
| } | ||
|
|
||
| /// Adds a row group to the metadata | ||
| /// | ||
| /// If the row groups are shared with another `ParquetMetaData`, this clones | ||
|
|
@@ -2329,6 +2341,54 @@ mod tests { | |
| assert!(!page_index.has_offset_indexes()); | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_set_key_value_metadata_preserves_shared_metadata() { | ||
| let original = vec![KeyValue::new("original".to_string(), "value".to_string())]; | ||
| let replacement = vec![KeyValue::new("replacement".to_string(), "new".to_string())]; | ||
| for initial in [None, Some(original)] { | ||
| let file_metadata = FileMetaData::new( | ||
| 2, | ||
| 0, | ||
| Some("test writer".to_string()), | ||
| initial.clone(), | ||
| get_test_schema_descr(), | ||
| None, | ||
| ); | ||
| #[cfg(feature = "encryption")] | ||
| let file_metadata = file_metadata | ||
| .with_encryption_algorithm(Some(EncryptionAlgorithm::AES_GCM_V1( | ||
| crate::file::metadata::thrift::encryption::AesGcmV1 { | ||
| aad_prefix: Some(vec![1; 8]), | ||
| aad_file_unique: Some(vec![2; 8]), | ||
| supply_aad_prefix: Some(true), | ||
| }, | ||
| ))) | ||
| .with_footer_signing_key_metadata(Some(vec![3; 8])); | ||
| let cached = ParquetMetaDataBuilder::new(file_metadata) | ||
| .set_page_index(Some(Arc::new(PageIndexBuilder::new(0, 2).build()))) | ||
| .build(); | ||
| for values in [None, Some(vec![]), Some(replacement.clone())] { | ||
| let updated = cached | ||
| .clone() | ||
| .into_builder() | ||
| .set_key_value_metadata(values.clone()) | ||
| .build(); | ||
| let mut expected = cached.file_metadata().clone(); | ||
| expected.key_value_metadata = values; | ||
| assert_eq!(updated.file_metadata(), &expected); | ||
| assert_eq!( | ||
| cached.file_metadata().key_value_metadata(), | ||
| initial.as_ref() | ||
| ); | ||
| assert!(Arc::ptr_eq(&cached.row_groups, &updated.row_groups)); | ||
| assert!(Arc::ptr_eq( | ||
| cached.page_index().unwrap(), | ||
| updated.page_index().unwrap() | ||
| )); | ||
| } | ||
| } | ||
| } | ||
|
|
||
| #[test] | ||
| fn test_replace_page_index_preserves_shared_metadata() { | ||
| let schema_descr = get_test_schema_descr(); | ||
|
|
||
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
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.
this is consistent with the other APIs to set the metadata like
arrow-rs/parquet/src/file/properties.rs
Lines 872 to 876 in 08651bc