This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 514735b038 Add example for how to read encrypted parquet files (#7283)
514735b038 is described below
commit 514735b038065a9a23ccdf869fd4fd02039d9476
Author: Rok Mihevc <[email protected]>
AuthorDate: Fri Mar 14 22:07:59 2025 +0100
Add example for how to read encrypted parquet files (#7283)
* Add decryption example to parquet docs
* Always build docs as if we have encryption enabled
* Check if encryption is enabled when building encryption example docs
* Update parquet/src/arrow/mod.rs
Co-authored-by: Adam Reeve <[email protected]>
* Remove uniform encryption example, better comments
* Update parquet/src/arrow/mod.rs
Co-authored-by: Adam Reeve <[email protected]>
* Review feedback
* Change to assert_eq! and whitespace obsession
---------
Co-authored-by: Adam Reeve <[email protected]>
Co-authored-by: Andrew Lamb <[email protected]>
---
parquet/src/arrow/mod.rs | 52 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 52 insertions(+)
diff --git a/parquet/src/arrow/mod.rs b/parquet/src/arrow/mod.rs
index 35f5897c18..e3f09a0dce 100644
--- a/parquet/src/arrow/mod.rs
+++ b/parquet/src/arrow/mod.rs
@@ -93,6 +93,58 @@
//!
//! println!("Read {} records.", record_batch.num_rows());
//! ```
+//!
+//! # Example of reading non-uniformly encrypted parquet file into arrow
record batch
+//!
+//! Note: This requires the experimental `encryption` feature to be enabled at
compile time.
+//!
+//!
+#![cfg_attr(feature = "encryption", doc = "```rust")]
+#![cfg_attr(not(feature = "encryption"), doc = "```ignore")]
+//! # use arrow_array::{Int32Array, ArrayRef};
+//! # use arrow_array::{types, RecordBatch};
+//! # use parquet::arrow::arrow_reader::{
+//! # ArrowReaderMetadata, ArrowReaderOptions,
ParquetRecordBatchReaderBuilder,
+//! # };
+//! # use arrow_array::cast::AsArray;
+//! # use parquet::file::metadata::ParquetMetaData;
+//! # use tempfile::tempfile;
+//! # use std::fs::File;
+//! # use parquet::encryption::decrypt::FileDecryptionProperties;
+//! # let test_data = arrow::util::test_util::parquet_test_data();
+//! # let path =
format!("{test_data}/encrypt_columns_and_footer.parquet.encrypted");
+//! #
+//! let file = File::open(path).unwrap();
+//!
+//! // Define the AES encryption keys required required for decrypting the
footer metadata
+//! // and column-specific data. If only a footer key is used then it is
assumed that the
+//! // file uses uniform encryption and all columns are encrypted with the
footer key.
+//! // If any column keys are specified, other columns without a key provided
are assumed
+//! // to be unencrypted
+//! let footer_key = "0123456789012345".as_bytes(); // Keys are 128 bits (16
bytes)
+//! let column_1_key = "1234567890123450".as_bytes();
+//! let column_2_key = "1234567890123451".as_bytes();
+//!
+//! let decryption_properties =
FileDecryptionProperties::builder(footer_key.to_vec())
+//! .with_column_key("double_field", column_1_key.to_vec())
+//! .with_column_key("float_field", column_2_key.to_vec())
+//! .build()
+//! .unwrap();
+//!
+//! let options = ArrowReaderOptions::default()
+//! .with_file_decryption_properties(decryption_properties);
+//! let reader_metadata = ArrowReaderMetadata::load(&file,
options.clone()).unwrap();
+//! let file_metadata = reader_metadata.metadata().file_metadata();
+//! assert_eq!(50, file_metadata.num_rows());
+//!
+//! let mut reader =
ParquetRecordBatchReaderBuilder::try_new_with_options(file, options)
+//! .unwrap()
+//! .build()
+//! .unwrap();
+//!
+//! let record_batch = reader.next().unwrap().unwrap();
+//! assert_eq!(50, record_batch.num_rows());
+//! ```
experimental!(mod array_reader);
pub mod arrow_reader;