Skip to content

Commit 9a304ca

Browse files
committed
Move TableEncryption into kms_encryption.rs
Signed-off-by: Corwin Joy <[email protected]>
1 parent ada7ab7 commit 9a304ca

File tree

5 files changed

+65
-77
lines changed

5 files changed

+65
-77
lines changed

crates/core/src/operations/encryption.rs

Lines changed: 0 additions & 69 deletions
This file was deleted.

crates/core/src/operations/mod.rs

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,8 +59,6 @@ pub mod constraints;
5959
#[cfg(feature = "datafusion")]
6060
pub mod delete;
6161
#[cfg(feature = "datafusion")]
62-
pub mod encryption;
63-
#[cfg(feature = "datafusion")]
6462
mod load;
6563
#[cfg(feature = "datafusion")]
6664
pub mod load_cdf;

crates/core/src/test_utils/kms_encryption.rs

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
use crate::operations::encryption::TableEncryption;
21
use crate::table::file_format_options::{
32
FileFormatOptions, TableOptions, WriterPropertiesFactory, WriterPropertiesFactoryRef,
43
};
54
use crate::{crate_version, DeltaResult};
65
use arrow_schema::Schema as ArrowSchema;
76
use async_trait::async_trait;
87
use datafusion::catalog::Session;
8+
use datafusion::config::{ConfigField, EncryptionFactoryOptions, ExtensionOptions};
9+
use datafusion::execution::parquet_encryption::EncryptionFactory;
910
use object_store::path::Path;
1011
use parquet::basic::Compression;
1112
use parquet::file::properties::{WriterProperties, WriterPropertiesBuilder};
@@ -14,11 +15,71 @@ use std::fmt::{Debug, Formatter};
1415
use std::sync::Arc;
1516
use uuid::Uuid;
1617

18+
pub type SchemaRef = Arc<ArrowSchema>;
19+
20+
#[derive(Clone, Debug)]
21+
pub struct TableEncryption {
22+
encryption_factory: Arc<dyn EncryptionFactory>,
23+
configuration: EncryptionFactoryOptions,
24+
}
25+
26+
impl TableEncryption {
27+
pub fn new(
28+
encryption_factory: Arc<dyn EncryptionFactory>,
29+
configuration: EncryptionFactoryOptions,
30+
) -> Self {
31+
Self {
32+
encryption_factory,
33+
configuration,
34+
}
35+
}
36+
37+
pub fn new_with_extension_options<T: ExtensionOptions>(
38+
encryption_factory: Arc<dyn EncryptionFactory>,
39+
options: &T,
40+
) -> DeltaResult<Self> {
41+
let mut configuration = EncryptionFactoryOptions::default();
42+
for entry in options.entries() {
43+
if let Some(value) = &entry.value {
44+
configuration.set(&entry.key, value)?;
45+
}
46+
}
47+
Ok(Self {
48+
encryption_factory,
49+
configuration,
50+
})
51+
}
52+
53+
pub fn encryption_factory(&self) -> &Arc<dyn EncryptionFactory> {
54+
&self.encryption_factory
55+
}
56+
57+
pub fn configuration(&self) -> &EncryptionFactoryOptions {
58+
&self.configuration
59+
}
60+
61+
pub async fn update_writer_properties(
62+
&self,
63+
mut builder: WriterPropertiesBuilder,
64+
file_path: &Path,
65+
file_schema: &SchemaRef,
66+
) -> DeltaResult<WriterPropertiesBuilder> {
67+
let encryption_properties = self
68+
.encryption_factory
69+
.get_file_encryption_properties(&self.configuration, file_schema, file_path)
70+
.await?;
71+
if let Some(encryption_properties) = encryption_properties {
72+
builder = builder.with_file_encryption_properties(encryption_properties);
73+
}
74+
Ok(builder)
75+
}
76+
}
77+
1778
// More advanced factory with KMS support
1879
#[derive(Clone, Debug)]
1980
pub struct KMSWriterPropertiesFactory {
2081
writer_properties: WriterProperties,
21-
encryption: Option<crate::operations::encryption::TableEncryption>,
82+
encryption: Option<TableEncryption>,
2283
}
2384

2485
impl KMSWriterPropertiesFactory {

crates/core/tests/commands_with_encryption.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,10 +12,9 @@ use datafusion::{
1212
};
1313
use deltalake_core::kernel::{DataType, PrimitiveType, StructField};
1414
use deltalake_core::operations::collect_sendable_stream;
15-
use deltalake_core::operations::encryption::TableEncryption;
1615
use deltalake_core::parquet::encryption::decrypt::FileDecryptionProperties;
1716
use deltalake_core::table::file_format_options::{FileFormatRef, SimpleFileFormatOptions};
18-
use deltalake_core::test_utils::kms_encryption::KmsFileFormatOptions;
17+
use deltalake_core::test_utils::kms_encryption::{KmsFileFormatOptions, TableEncryption};
1918
use deltalake_core::{arrow, parquet, DeltaOps};
2019
use deltalake_core::{operations::optimize::OptimizeType, DeltaTable, DeltaTableError};
2120
use parquet_key_management::datafusion::{KmsEncryptionFactory, KmsEncryptionFactoryOptions};

crates/deltalake/examples/basic_operations_encryption.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,9 +14,8 @@ use deltalake::kernel::{DataType, PrimitiveType, StructField};
1414
use deltalake::operations::collect_sendable_stream;
1515
use deltalake::parquet::encryption::decrypt::FileDecryptionProperties;
1616
use deltalake::{arrow, parquet, DeltaOps};
17-
use deltalake_core::operations::encryption::TableEncryption;
1817
use deltalake_core::table::file_format_options::{FileFormatRef, SimpleFileFormatOptions};
19-
use deltalake_core::test_utils::kms_encryption::KmsFileFormatOptions;
18+
use deltalake_core::test_utils::kms_encryption::{KmsFileFormatOptions, TableEncryption};
2019
use deltalake_core::{
2120
datafusion::common::test_util::format_batches, operations::optimize::OptimizeType, DeltaTable,
2221
DeltaTableError,

0 commit comments

Comments
 (0)