@@ -425,10 +425,7 @@ impl DataSink for ParquetSink {
425425
426426 let input = ctx. encode_child ( exec. input ( ) ) ?;
427427 let sort_order = exec. encode_sort_order ( ctx) ?;
428- let sink = protobuf:: ParquetSink {
429- config : Some ( ( & self . config ) . try_into ( ) ?) ,
430- parquet_options : Some ( self . parquet_options ( ) . try_into ( ) ?) ,
431- } ;
428+ let sink = protobuf:: ParquetSink :: try_from ( self ) ?;
432429 let node = protobuf:: ParquetSinkExecNode {
433430 input : Some ( Box :: new ( input) ) ,
434431 sink : Some ( sink) ,
@@ -441,6 +438,43 @@ impl DataSink for ParquetSink {
441438 }
442439}
443440
441+ #[ cfg( feature = "proto" ) ]
442+ impl TryFrom < & ParquetSink > for datafusion_proto_models:: protobuf:: ParquetSink {
443+ type Error = DataFusionError ;
444+
445+ fn try_from ( value : & ParquetSink ) -> Result < Self > {
446+ Ok ( Self {
447+ config : Some ( value. config ( ) . try_into ( ) ?) ,
448+ parquet_options : Some ( value. parquet_options ( ) . try_into ( ) ?) ,
449+ } )
450+ }
451+ }
452+
453+ #[ cfg( feature = "proto" ) ]
454+ impl TryFrom < & datafusion_proto_models:: protobuf:: ParquetSink > for ParquetSink {
455+ type Error = DataFusionError ;
456+
457+ fn try_from ( value : & datafusion_proto_models:: protobuf:: ParquetSink ) -> Result < Self > {
458+ let config =
459+ FileSinkConfig :: try_from ( value. config . as_ref ( ) . ok_or_else ( || {
460+ datafusion_common:: internal_datafusion_err!(
461+ "ParquetSink is missing required field 'config'"
462+ )
463+ } ) ?) ?;
464+ let parquet_options = value
465+ . parquet_options
466+ . as_ref ( )
467+ . ok_or_else ( || {
468+ datafusion_common:: internal_datafusion_err!(
469+ "ParquetSink is missing required field 'parquet_options'"
470+ )
471+ } ) ?
472+ . try_into ( ) ?;
473+
474+ Ok ( Self :: new ( config, parquet_options) )
475+ }
476+ }
477+
444478#[ cfg( feature = "proto" ) ]
445479impl ParquetSink {
446480 /// Reconstructs a [`DataSinkExec`] containing a `ParquetSink` from protobuf.
@@ -450,16 +484,11 @@ impl ParquetSink {
450484 ) -> Result < Arc < dyn ExecutionPlan > > {
451485 use datafusion_proto_models:: protobuf;
452486
453- let sink_node = match & node. physical_plan_type {
454- Some ( protobuf:: physical_plan_node:: PhysicalPlanType :: ParquetSink ( sink) ) => {
455- sink. as_ref ( )
456- }
457- _ => {
458- return datafusion_common:: internal_err!(
459- "PhysicalPlanNode is not a ParquetSink"
460- ) ;
461- }
462- } ;
487+ let sink_node = datafusion_physical_plan:: expect_plan_variant!(
488+ node,
489+ protobuf:: physical_plan_node:: PhysicalPlanType :: ParquetSink ,
490+ "ParquetSink" ,
491+ ) ;
463492 let input = ctx. decode_required_child (
464493 sink_node. input . as_deref ( ) ,
465494 "ParquetSinkExecNode" ,
@@ -470,22 +499,7 @@ impl ParquetSink {
470499 "ParquetSinkExecNode is missing required field 'sink'"
471500 )
472501 } ) ?;
473- let config =
474- FileSinkConfig :: try_from ( proto_sink. config . as_ref ( ) . ok_or_else ( || {
475- datafusion_common:: internal_datafusion_err!(
476- "ParquetSink is missing required field 'config'"
477- )
478- } ) ?) ?;
479- let parquet_options = proto_sink
480- . parquet_options
481- . as_ref ( )
482- . ok_or_else ( || {
483- datafusion_common:: internal_datafusion_err!(
484- "ParquetSink is missing required field 'parquet_options'"
485- )
486- } ) ?
487- . try_into ( ) ?;
488- let data_sink = ParquetSink :: new ( config, parquet_options) ;
502+ let data_sink = ParquetSink :: try_from ( proto_sink) ?;
489503 let sort_order = DataSinkExec :: decode_sort_order (
490504 sink_node. sort_order . as_ref ( ) ,
491505 ctx,
0 commit comments