1- use crate :: operations:: encryption:: TableEncryption ;
21use crate :: table:: file_format_options:: {
32 FileFormatOptions , TableOptions , WriterPropertiesFactory , WriterPropertiesFactoryRef ,
43} ;
54use crate :: { crate_version, DeltaResult } ;
65use arrow_schema:: Schema as ArrowSchema ;
76use async_trait:: async_trait;
87use datafusion:: catalog:: Session ;
8+ use datafusion:: config:: { ConfigField , EncryptionFactoryOptions , ExtensionOptions } ;
9+ use datafusion:: execution:: parquet_encryption:: EncryptionFactory ;
910use object_store:: path:: Path ;
1011use parquet:: basic:: Compression ;
1112use parquet:: file:: properties:: { WriterProperties , WriterPropertiesBuilder } ;
@@ -14,11 +15,71 @@ use std::fmt::{Debug, Formatter};
1415use std:: sync:: Arc ;
1516use 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 ) ]
1980pub struct KMSWriterPropertiesFactory {
2081 writer_properties : WriterProperties ,
21- encryption : Option < crate :: operations :: encryption :: TableEncryption > ,
82+ encryption : Option < TableEncryption > ,
2283}
2384
2485impl KMSWriterPropertiesFactory {
0 commit comments