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