-
Notifications
You must be signed in to change notification settings - Fork 1.5k
feat: Parquet modular encryption #16351
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
corwinjoy
wants to merge
38
commits into
apache:main
Choose a base branch
from
corwinjoy:parquet_encryption
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.
+914
−29
Open
Changes from all commits
Commits
Show all changes
38 commits
Select commit
Hold shift + click to select a range
e668b99
Initial commit to form PR for datafusion encryption support
corwinjoy d38dba4
Add tests for encryption configuration
corwinjoy 5a2b456
Apply cargo fmt
corwinjoy c972676
Add a roundtrip encryption test to the parquet tests.
corwinjoy ec3f828
cargo fmt
corwinjoy 3538a27
Update test to add decryption parameter to called functions.
corwinjoy a754992
Try to get DataFrame.write_parquet to work with encryption. Doesn't q…
corwinjoy e430672
Update datafusion/datasource-parquet/src/opener.rs
corwinjoy 7fcba70
Update datafusion/datasource-parquet/src/source.rs
corwinjoy d6b1fca
Fix write test in parquet.rs
corwinjoy 3353186
Simplify encryption test. Remove unused imports.
corwinjoy e4bc0e3
Run cargo fmt.
corwinjoy f52e79c
Further streamline roundtrip test.
corwinjoy 5615ac8
Change From methods for FileEncryptionProperties and FileDecryptionPr…
corwinjoy 61bc78e
Change encryption config to directly hold column keys using custom co…
corwinjoy a81855f
Fix generated field names in visit for encryptor and decryptor to use…
corwinjoy 4cf12b3
1. Disable parallel writes with enccryption.
corwinjoy f29bec3
cargo fmt
corwinjoy 86fe04b
Update datafusion/common/src/file_options/parquet_writer.rs
corwinjoy d4ea63f
fix variables shown in information schema test.
corwinjoy 0fcc4a5
Merge remote-tracking branch 'origin/parquet_encryption' into parquet…
corwinjoy 86db3a5
Backout bad suggestion from copilot
corwinjoy b34441a
Remove unused serde reference
corwinjoy 668d728
cargo fmt
corwinjoy ec1e8da
change file_format.rs to use global encryption options in struct.
corwinjoy e233408
Turn off page_index for encrypted example. Get encrypted example work…
corwinjoy 9ffaae4
Tidy up example output.
corwinjoy 8e244e9
Add missing license. Run taplo format
corwinjoy 2871d51
Update configs.md by running dev/update_config_docs.sh
corwinjoy c405167
Cargo fmt + clippy changes.
corwinjoy 506801e
Add filter test for encrypted files.
corwinjoy 3058a90
Cargo clippy changes.
corwinjoy e7e521a
Merge remote-tracking branch 'origin/main' into parquet_encryption
corwinjoy bbeecfe
Fix link in README.md
corwinjoy 4ceb072
Add issue tag for parallel writes.
corwinjoy c998378
Move file encryption and decryption properties out of global options
adamreeve 7780b33
Use config_namespace_with_hashmap for column encryption/decryption props
adamreeve 219d0b3
Merge pull request #5 from adamreeve/crypto_config_namespace
corwinjoy 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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
@@ -0,0 +1,118 @@ | ||
// Licensed to the Apache Software Foundation (ASF) under one | ||
// or more contributor license agreements. See the NOTICE file | ||
// distributed with this work for additional information | ||
// regarding copyright ownership. The ASF licenses this file | ||
// to you under the Apache License, Version 2.0 (the | ||
// "License"); you may not use this file except in compliance | ||
// with the License. You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, | ||
// software distributed under the License is distributed on an | ||
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY | ||
// KIND, either express or implied. See the License for the | ||
// specific language governing permissions and limitations | ||
// under the License. | ||
|
||
use datafusion::common::DataFusionError; | ||
use datafusion::config::TableParquetOptions; | ||
use datafusion::dataframe::{DataFrame, DataFrameWriteOptions}; | ||
use datafusion::logical_expr::{col, lit}; | ||
use datafusion::parquet::encryption::decrypt::FileDecryptionProperties; | ||
use datafusion::parquet::encryption::encrypt::FileEncryptionProperties; | ||
use datafusion::prelude::{ParquetReadOptions, SessionContext}; | ||
use tempfile::TempDir; | ||
|
||
#[tokio::main] | ||
async fn main() -> datafusion::common::Result<()> { | ||
// The SessionContext is the main high level API for interacting with DataFusion | ||
let ctx = SessionContext::new(); | ||
|
||
// Find the local path of "alltypes_plain.parquet" | ||
let testdata = datafusion::test_util::parquet_test_data(); | ||
let filename = &format!("{testdata}/alltypes_plain.parquet"); | ||
|
||
// Read the sample parquet file | ||
let parquet_df = ctx | ||
.read_parquet(filename, ParquetReadOptions::default()) | ||
.await?; | ||
|
||
// Show information from the dataframe | ||
println!( | ||
"===============================================================================" | ||
); | ||
println!("Original Parquet DataFrame:"); | ||
query_dataframe(&parquet_df).await?; | ||
|
||
// Setup encryption and decryption properties | ||
let (encrypt, decrypt) = setup_encryption(&parquet_df)?; | ||
|
||
// Create a temporary file location for the encrypted parquet file | ||
let tmp_dir = TempDir::new()?; | ||
let tempfile = tmp_dir.path().join("alltypes_plain-encrypted.parquet"); | ||
let tempfile_str = tempfile.into_os_string().into_string().unwrap(); | ||
|
||
// Write encrypted parquet | ||
let mut options = TableParquetOptions::default(); | ||
options.crypto.file_encryption = Some((&encrypt).into()); | ||
parquet_df | ||
.write_parquet( | ||
tempfile_str.as_str(), | ||
DataFrameWriteOptions::new().with_single_file_output(true), | ||
Some(options), | ||
) | ||
.await?; | ||
|
||
// Read encrypted parquet | ||
let ctx: SessionContext = SessionContext::new(); | ||
let read_options = ParquetReadOptions::default().file_decryption_properties(decrypt); | ||
|
||
let encrypted_parquet_df = ctx.read_parquet(tempfile_str, read_options).await?; | ||
|
||
// Show information from the dataframe | ||
println!("\n\n==============================================================================="); | ||
println!("Encrypted Parquet DataFrame:"); | ||
query_dataframe(&encrypted_parquet_df).await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
// Show information from the dataframe | ||
async fn query_dataframe(df: &DataFrame) -> Result<(), DataFusionError> { | ||
// show its schema using 'describe' | ||
println!("Schema:"); | ||
df.clone().describe().await?.show().await?; | ||
|
||
// Select three columns and filter the results | ||
// so that only rows where id > 1 are returned | ||
println!("\nSelected rows and columns:"); | ||
df.clone() | ||
.select_columns(&["id", "bool_col", "timestamp_col"])? | ||
.filter(col("id").gt(lit(5)))? | ||
.show() | ||
.await?; | ||
|
||
Ok(()) | ||
} | ||
|
||
// Setup encryption and decryption properties | ||
fn setup_encryption( | ||
parquet_df: &DataFrame, | ||
) -> Result<(FileEncryptionProperties, FileDecryptionProperties), DataFusionError> { | ||
let schema = parquet_df.schema(); | ||
let footer_key = b"0123456789012345".to_vec(); // 128bit/16 | ||
let column_key = b"1234567890123450".to_vec(); // 128bit/16 | ||
|
||
let mut encrypt = FileEncryptionProperties::builder(footer_key.clone()); | ||
let mut decrypt = FileDecryptionProperties::builder(footer_key.clone()); | ||
|
||
for field in schema.fields().iter() { | ||
encrypt = encrypt.with_column_key(field.name().as_str(), column_key.clone()); | ||
decrypt = decrypt.with_column_key(field.name().as_str(), column_key.clone()); | ||
} | ||
|
||
let encrypt = encrypt.build()?; | ||
let decrypt = decrypt.build()?; | ||
Ok((encrypt, decrypt)) | ||
} |
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.
requested by clippy