@@ -1089,6 +1089,16 @@ impl TryFrom<&protobuf::ParquetOptions> for ParquetOptions {
10891089 max_predicate_cache_size : value. max_predicate_cache_size_opt . map ( |opt| match opt {
10901090 protobuf:: parquet_options:: MaxPredicateCacheSizeOpt :: MaxPredicateCacheSize ( v) => Some ( v as usize ) ,
10911091 } ) . unwrap_or ( None ) ,
1092+ enable_content_defined_chunking : value. content_defined_chunking ,
1093+ cdc_min_chunk_size : value. cdc_min_chunk_size_opt . map ( |opt| match opt {
1094+ protobuf:: parquet_options:: CdcMinChunkSizeOpt :: CdcMinChunkSize ( v) => v as usize ,
1095+ } ) . unwrap_or ( ParquetOptions :: default ( ) . cdc_min_chunk_size ) ,
1096+ cdc_max_chunk_size : value. cdc_max_chunk_size_opt . map ( |opt| match opt {
1097+ protobuf:: parquet_options:: CdcMaxChunkSizeOpt :: CdcMaxChunkSize ( v) => v as usize ,
1098+ } ) . unwrap_or ( ParquetOptions :: default ( ) . cdc_max_chunk_size ) ,
1099+ cdc_norm_level : value. cdc_norm_level_opt . map ( |opt| match opt {
1100+ protobuf:: parquet_options:: CdcNormLevelOpt :: CdcNormLevel ( v) => v as i64 ,
1101+ } ) . unwrap_or ( ParquetOptions :: default ( ) . cdc_norm_level ) ,
10921102 } )
10931103 }
10941104}
@@ -1151,17 +1161,17 @@ impl TryFrom<&protobuf::TableParquetOptions> for TableParquetOptions {
11511161 column_specific_options. insert ( column_name. clone ( ) , options. try_into ( ) ?) ;
11521162 }
11531163 }
1154- Ok ( TableParquetOptions {
1164+ let opts = TableParquetOptions {
11551165 global : value
11561166 . global
11571167 . as_ref ( )
11581168 . map ( |v| v. try_into ( ) )
11591169 . unwrap ( )
11601170 . unwrap ( ) ,
11611171 column_specific_options,
1162- key_value_metadata : Default :: default ( ) ,
1163- crypto : Default :: default ( ) ,
1164- } )
1172+ .. Default :: default ( )
1173+ } ;
1174+ Ok ( opts )
11651175 }
11661176}
11671177
@@ -1261,3 +1271,89 @@ pub(crate) fn csv_writer_options_from_proto(
12611271 . with_null ( writer_options. null_value . clone ( ) )
12621272 . with_double_quote ( writer_options. double_quote ) )
12631273}
1274+
1275+ #[ cfg( test) ]
1276+ mod tests {
1277+ use super :: * ;
1278+ use datafusion_common:: config:: { ParquetOptions , TableParquetOptions } ;
1279+
1280+ fn parquet_options_proto_round_trip ( opts : ParquetOptions ) -> ParquetOptions {
1281+ let proto: crate :: protobuf_common:: ParquetOptions =
1282+ ( & opts) . try_into ( ) . expect ( "to_proto" ) ;
1283+ ParquetOptions :: try_from ( & proto) . expect ( "from_proto" )
1284+ }
1285+
1286+ fn table_parquet_options_proto_round_trip (
1287+ opts : TableParquetOptions ,
1288+ ) -> TableParquetOptions {
1289+ let proto: crate :: protobuf_common:: TableParquetOptions =
1290+ ( & opts) . try_into ( ) . expect ( "to_proto" ) ;
1291+ TableParquetOptions :: try_from ( & proto) . expect ( "from_proto" )
1292+ }
1293+
1294+ #[ test]
1295+ fn test_parquet_options_cdc_disabled_round_trip ( ) {
1296+ let opts = ParquetOptions :: default ( ) ;
1297+ assert ! ( !opts. enable_content_defined_chunking) ;
1298+ let recovered = parquet_options_proto_round_trip ( opts. clone ( ) ) ;
1299+ assert_eq ! ( opts, recovered) ;
1300+ }
1301+
1302+ #[ test]
1303+ fn test_parquet_options_cdc_enabled_round_trip ( ) {
1304+ let opts = ParquetOptions {
1305+ enable_content_defined_chunking : true ,
1306+ cdc_min_chunk_size : 128 * 1024 ,
1307+ cdc_max_chunk_size : 512 * 1024 ,
1308+ cdc_norm_level : 2 ,
1309+ ..ParquetOptions :: default ( )
1310+ } ;
1311+ let recovered = parquet_options_proto_round_trip ( opts. clone ( ) ) ;
1312+ assert_eq ! ( recovered. enable_content_defined_chunking, true ) ;
1313+ assert_eq ! ( recovered. cdc_min_chunk_size, 128 * 1024 ) ;
1314+ assert_eq ! ( recovered. cdc_max_chunk_size, 512 * 1024 ) ;
1315+ assert_eq ! ( recovered. cdc_norm_level, 2 ) ;
1316+ }
1317+
1318+ #[ test]
1319+ fn test_parquet_options_cdc_negative_norm_level_round_trip ( ) {
1320+ let opts = ParquetOptions {
1321+ enable_content_defined_chunking : true ,
1322+ cdc_norm_level : -3 ,
1323+ ..ParquetOptions :: default ( )
1324+ } ;
1325+ let recovered = parquet_options_proto_round_trip ( opts) ;
1326+ assert_eq ! ( recovered. cdc_norm_level, -3 ) ;
1327+ }
1328+
1329+ #[ test]
1330+ fn test_table_parquet_options_cdc_round_trip ( ) {
1331+ let mut opts = TableParquetOptions :: default ( ) ;
1332+ opts. global . enable_content_defined_chunking = true ;
1333+ opts. global . cdc_min_chunk_size = 64 * 1024 ;
1334+ opts. global . cdc_max_chunk_size = 2 * 1024 * 1024 ;
1335+ opts. global . cdc_norm_level = -1 ;
1336+
1337+ let recovered = table_parquet_options_proto_round_trip ( opts. clone ( ) ) ;
1338+ assert_eq ! ( recovered. global. enable_content_defined_chunking, true ) ;
1339+ assert_eq ! ( recovered. global. cdc_min_chunk_size, 64 * 1024 ) ;
1340+ assert_eq ! ( recovered. global. cdc_max_chunk_size, 2 * 1024 * 1024 ) ;
1341+ assert_eq ! ( recovered. global. cdc_norm_level, -1 ) ;
1342+ }
1343+
1344+ #[ test]
1345+ fn test_table_parquet_options_cdc_disabled_round_trip ( ) {
1346+ let opts = TableParquetOptions :: default ( ) ;
1347+ assert ! ( !opts. global. enable_content_defined_chunking) ;
1348+ let recovered = table_parquet_options_proto_round_trip ( opts. clone ( ) ) ;
1349+ assert_eq ! ( recovered. global. enable_content_defined_chunking, false ) ;
1350+ assert_eq ! (
1351+ recovered. global. cdc_min_chunk_size,
1352+ ParquetOptions :: default ( ) . cdc_min_chunk_size
1353+ ) ;
1354+ assert_eq ! (
1355+ recovered. global. cdc_max_chunk_size,
1356+ ParquetOptions :: default ( ) . cdc_max_chunk_size
1357+ ) ;
1358+ }
1359+ }
0 commit comments