|
93 | 93 | //!
|
94 | 94 | //! println!("Read {} records.", record_batch.num_rows());
|
95 | 95 | //! ```
|
| 96 | +//! |
| 97 | +//! # Example of reading non-uniformly encrypted parquet file into arrow record batch |
| 98 | +//! |
| 99 | +//! Note: This requires the experimental `encryption` feature to be enabled at compile time. |
| 100 | +//! |
| 101 | +//! |
| 102 | +#![cfg_attr(feature = "encryption", doc = "```rust")] |
| 103 | +#![cfg_attr(not(feature = "encryption"), doc = "```ignore")] |
| 104 | +//! # use arrow_array::{Int32Array, ArrayRef}; |
| 105 | +//! # use arrow_array::{types, RecordBatch}; |
| 106 | +//! # use parquet::arrow::arrow_reader::{ |
| 107 | +//! # ArrowReaderMetadata, ArrowReaderOptions, ParquetRecordBatchReaderBuilder, |
| 108 | +//! # }; |
| 109 | +//! # use arrow_array::cast::AsArray; |
| 110 | +//! # use parquet::file::metadata::ParquetMetaData; |
| 111 | +//! # use tempfile::tempfile; |
| 112 | +//! # use std::fs::File; |
| 113 | +//! # use parquet::encryption::decrypt::FileDecryptionProperties; |
| 114 | +//! # let test_data = arrow::util::test_util::parquet_test_data(); |
| 115 | +//! # let path = format!("{test_data}/encrypt_columns_and_footer.parquet.encrypted"); |
| 116 | +//! # |
| 117 | +//! let file = File::open(path).unwrap(); |
| 118 | +//! |
| 119 | +//! // Define the AES encryption keys required required for decrypting the footer metadata |
| 120 | +//! // and column-specific data. If only a footer key is used then it is assumed that the |
| 121 | +//! // file uses uniform encryption and all columns are encrypted with the footer key. |
| 122 | +//! // If any column keys are specified, other columns without a key provided are assumed |
| 123 | +//! // to be unencrypted |
| 124 | +//! let footer_key = "0123456789012345".as_bytes(); // Keys are 128 bits (16 bytes) |
| 125 | +//! let column_1_key = "1234567890123450".as_bytes(); |
| 126 | +//! let column_2_key = "1234567890123451".as_bytes(); |
| 127 | +//! |
| 128 | +//! let decryption_properties = FileDecryptionProperties::builder(footer_key.to_vec()) |
| 129 | +//! .with_column_key("double_field", column_1_key.to_vec()) |
| 130 | +//! .with_column_key("float_field", column_2_key.to_vec()) |
| 131 | +//! .build() |
| 132 | +//! .unwrap(); |
| 133 | +//! |
| 134 | +//! let options = ArrowReaderOptions::default() |
| 135 | +//! .with_file_decryption_properties(decryption_properties); |
| 136 | +//! let reader_metadata = ArrowReaderMetadata::load(&file, options.clone()).unwrap(); |
| 137 | +//! let file_metadata = reader_metadata.metadata().file_metadata(); |
| 138 | +//! assert_eq!(50, file_metadata.num_rows()); |
| 139 | +//! |
| 140 | +//! let mut reader = ParquetRecordBatchReaderBuilder::try_new_with_options(file, options) |
| 141 | +//! .unwrap() |
| 142 | +//! .build() |
| 143 | +//! .unwrap(); |
| 144 | +//! |
| 145 | +//! let record_batch = reader.next().unwrap().unwrap(); |
| 146 | +//! assert_eq!(50, record_batch.num_rows()); |
| 147 | +//! ``` |
96 | 148 |
|
97 | 149 | experimental!(mod array_reader);
|
98 | 150 | pub mod arrow_reader;
|
|
0 commit comments