|
93 | 93 | //!
|
94 | 94 | //! println!("Read {} records.", record_batch.num_rows());
|
95 | 95 | //! ```
|
| 96 | +//! |
| 97 | +//! # Example of reading uniformly encrypted parquet file into arrow record batch |
| 98 | +//! |
| 99 | +#![cfg_attr(feature = "encryption", doc = "```rust")] |
| 100 | +#![cfg_attr(not(feature = "encryption"), doc = "```ignore")] |
| 101 | +//! # use arrow_array::{Int32Array, ArrayRef}; |
| 102 | +//! # use arrow_array::{types, RecordBatch}; |
| 103 | +//! # use parquet::arrow::arrow_reader::{ |
| 104 | +//! # ArrowReaderMetadata, ArrowReaderOptions, ParquetRecordBatchReaderBuilder, |
| 105 | +//! # }; |
| 106 | +//! # use arrow_array::cast::AsArray; |
| 107 | +//! # use parquet::file::metadata::ParquetMetaData; |
| 108 | +//! # use tempfile::tempfile; |
| 109 | +//! # use std::fs::File; |
| 110 | +//! # use parquet::encryption::decrypt::FileDecryptionProperties; |
| 111 | +//! # let test_data = arrow::util::test_util::parquet_test_data(); |
| 112 | +//! # let path = format!("{test_data}/uniform_encryption.parquet.encrypted"); |
| 113 | +//! # |
| 114 | +//! let file = File::open(path).unwrap(); |
| 115 | +//! |
| 116 | +//! let key_code: &[u8] = "0123456789012345".as_bytes(); |
| 117 | +//! let decryption_properties = FileDecryptionProperties::builder(key_code.to_vec()) |
| 118 | +//! .build() |
| 119 | +//! .unwrap(); |
| 120 | +//! |
| 121 | +//! let options = |
| 122 | +//! ArrowReaderOptions::default().with_file_decryption_properties(decryption_properties); |
| 123 | +//! let reader_metadata = ArrowReaderMetadata::load(&file, options.clone()).unwrap(); |
| 124 | +//! let metadata = reader_metadata.metadata(); |
| 125 | +//! let file_metadata = metadata.file_metadata(); |
| 126 | +//! |
| 127 | +//! println!("Read {} rows.", file_metadata.num_rows()); |
| 128 | +//! |
| 129 | +//! let builder = ParquetRecordBatchReaderBuilder::try_new_with_options(file, options).unwrap(); |
| 130 | +//! println!("Converted arrow schema is: {}", builder.schema()); |
| 131 | +//! |
| 132 | +//! let mut reader = builder.build().unwrap(); |
| 133 | +//! |
| 134 | +//! let record_batch = reader.next().unwrap().unwrap(); |
| 135 | +//! |
| 136 | +//! println!("Read {} records.", record_batch.num_rows()); |
| 137 | +//! ``` |
| 138 | +//! |
| 139 | +//! # Example of reading non-uniformly encrypted parquet file into arrow record batch |
| 140 | +//! |
| 141 | +#![cfg_attr(feature = "encryption", doc = "```rust")] |
| 142 | +#![cfg_attr(not(feature = "encryption"), doc = "```ignore")] |
| 143 | +//! # use arrow_array::{Int32Array, ArrayRef}; |
| 144 | +//! # use arrow_array::{types, RecordBatch}; |
| 145 | +//! # use parquet::arrow::arrow_reader::{ |
| 146 | +//! # ArrowReaderMetadata, ArrowReaderOptions, ParquetRecordBatchReaderBuilder, |
| 147 | +//! # }; |
| 148 | +//! # use arrow_array::cast::AsArray; |
| 149 | +//! # use parquet::file::metadata::ParquetMetaData; |
| 150 | +//! # use tempfile::tempfile; |
| 151 | +//! # use std::fs::File; |
| 152 | +//! # use parquet::encryption::decrypt::FileDecryptionProperties; |
| 153 | +//! # let test_data = arrow::util::test_util::parquet_test_data(); |
| 154 | +//! # let path = format!("{test_data}/encrypt_columns_and_footer.parquet.encrypted"); |
| 155 | +//! # |
| 156 | +//! let file = File::open(path).unwrap(); |
| 157 | +//! |
| 158 | +//! // There is always a footer key even with a plaintext footer, |
| 159 | +//! // but this is used for signing the footer. |
| 160 | +//! let footer_key = "0123456789012345".as_bytes(); // 128bit/16 |
| 161 | +//! let column_1_key = "1234567890123450".as_bytes(); |
| 162 | +//! let column_2_key = "1234567890123451".as_bytes(); |
| 163 | +//! |
| 164 | +//! let decryption_properties = FileDecryptionProperties::builder(footer_key.to_vec()) |
| 165 | +//! .with_column_key("double_field", column_1_key.to_vec()) |
| 166 | +//! .with_column_key("float_field", column_2_key.to_vec()) |
| 167 | +//! .build() |
| 168 | +//! .unwrap(); |
| 169 | +//! |
| 170 | +//! let options = |
| 171 | +//! ArrowReaderOptions::default().with_file_decryption_properties(decryption_properties); |
| 172 | +//! let reader_metadata = ArrowReaderMetadata::load(&file, options.clone()).unwrap(); |
| 173 | +//! let metadata = reader_metadata.metadata(); |
| 174 | +//! let file_metadata = metadata.file_metadata(); |
| 175 | +//! |
| 176 | +//! println!("Read {} rows.", file_metadata.num_rows()); |
| 177 | +//! |
| 178 | +//! let builder = ParquetRecordBatchReaderBuilder::try_new_with_options(file, options).unwrap(); |
| 179 | +//! println!("Converted arrow schema is: {}", builder.schema()); |
| 180 | +//! |
| 181 | +//! let mut reader = builder.build().unwrap(); |
| 182 | +//! |
| 183 | +//! let record_batch = reader.next().unwrap().unwrap(); |
| 184 | +//! |
| 185 | +//! println!("Read {} records.", record_batch.num_rows()); |
96 | 186 |
|
97 | 187 | experimental!(mod array_reader);
|
98 | 188 | pub mod arrow_reader;
|
|
0 commit comments