@@ -82,6 +82,7 @@ use datafusion::physical_plan::limit::{GlobalLimitExec, LocalLimitExec};
8282use datafusion:: physical_plan:: metrics:: MetricCategory ;
8383use datafusion:: physical_plan:: placeholder_row:: PlaceholderRowExec ;
8484use datafusion:: physical_plan:: projection:: { ProjectionExec , ProjectionExpr } ;
85+ use datafusion:: physical_plan:: proto:: ExecutionPlanEncodeCtx ;
8586use datafusion:: physical_plan:: repartition:: RepartitionExec ;
8687use datafusion:: physical_plan:: scalar_subquery:: {
8788 ScalarSubqueryExec , ScalarSubqueryLink ,
@@ -134,7 +135,6 @@ use datafusion_proto::bytes::{
134135 physical_plan_from_bytes_with_proto_converter,
135136 physical_plan_to_bytes_with_proto_converter,
136137} ;
137- use datafusion_proto:: convert:: TryFromProto ;
138138use datafusion_proto:: physical_plan:: to_proto:: serialize_physical_expr_with_converter;
139139use datafusion_proto:: physical_plan:: {
140140 AsExecutionPlan , DeduplicatingProtoConverter , DefaultPhysicalExtensionCodec ,
@@ -2083,10 +2083,11 @@ impl DataSink for ProtoHookSink {
20832083
20842084 fn try_to_proto (
20852085 & self ,
2086- input : PhysicalPlanNode ,
2087- sort_order : Option < protobuf:: PhysicalSortExprNodeCollection > ,
2088- sink_schema : & Schema ,
2086+ exec : & DataSinkExec ,
2087+ ctx : & ExecutionPlanEncodeCtx < ' _ > ,
20892088 ) -> Result < Option < PhysicalPlanNode > > {
2089+ let input = ctx. encode_child ( exec. input ( ) ) ?;
2090+ let sort_order = exec. encode_sort_order ( ctx) ?;
20902091 assert ! ( matches!(
20912092 input. physical_plan_type,
20922093 Some ( protobuf:: physical_plan_node:: PhysicalPlanType :: PlaceholderRow ( _) )
@@ -2097,13 +2098,13 @@ impl DataSink for ProtoHookSink {
20972098 . map( |ordering| ordering. physical_sort_expr_nodes. len( ) ) ,
20982099 Some ( 1 )
20992100 ) ;
2100- assert_eq ! ( sink_schema . fields( ) . len( ) , 1 ) ;
2101+ assert_eq ! ( exec . schema ( ) . fields( ) . len( ) , 1 ) ;
21012102
21022103 Ok ( Some ( PhysicalPlanNode {
21032104 physical_plan_type : Some (
21042105 protobuf:: physical_plan_node:: PhysicalPlanType :: Empty (
21052106 protobuf:: EmptyExecNode {
2106- schema : Some ( sink_schema . try_into ( ) ?) ,
2107+ schema : Some ( exec . schema ( ) . as_ref ( ) . try_into ( ) ?) ,
21072108 partitions : 1 ,
21082109 } ,
21092110 ) ,
@@ -2143,7 +2144,7 @@ fn data_sink_exec_delegates_to_sink_proto_hook() -> Result<()> {
21432144}
21442145
21452146#[ test]
2146- fn file_sink_config_conversion_preserves_compatibility_api ( ) -> Result < ( ) > {
2147+ fn file_sink_config_roundtrip_preserves_fields ( ) -> Result < ( ) > {
21472148 let schema = Arc :: new ( Schema :: new ( vec ! [ Field :: new(
21482149 "partition" ,
21492150 DataType :: Utf8 ,
@@ -2162,14 +2163,40 @@ fn file_sink_config_conversion_preserves_compatibility_api() -> Result<()> {
21622163 file_output_mode : FileOutputMode :: Directory ,
21632164 } ;
21642165
2165- let encoded = config. to_proto ( ) ?;
2166- let compatibility_encoded = protobuf:: FileSinkConfig :: try_from_proto ( & config) ?;
2167- assert_eq ! ( encoded, compatibility_encoded) ;
2166+ let encoded = protobuf:: FileSinkConfig :: try_from ( & config) ?;
2167+ assert_eq ! ( encoded. insert_op( ) , protobuf:: InsertOp :: Overwrite ) ;
2168+ assert_eq ! (
2169+ encoded. file_output_mode( ) ,
2170+ protobuf:: FileOutputMode :: Directory
2171+ ) ;
21682172
2169- let decoded = FileSinkConfig :: from_proto ( & encoded) ?;
2170- let compatibility_decoded = FileSinkConfig :: try_from_proto ( & encoded) ?;
2171- assert_eq ! ( decoded. to_proto( ) ?, encoded) ;
2172- assert_eq ! ( compatibility_decoded. to_proto( ) ?, encoded) ;
2173+ let decoded = FileSinkConfig :: try_from ( & encoded) ?;
2174+ assert_eq ! ( decoded. object_store_url, config. object_store_url) ;
2175+ assert_eq ! ( decoded. table_paths, config. table_paths) ;
2176+ assert_eq ! (
2177+ decoded. output_schema. as_ref( ) ,
2178+ config. output_schema. as_ref( )
2179+ ) ;
2180+ assert_eq ! ( decoded. table_partition_cols, config. table_partition_cols) ;
2181+ assert_eq ! ( decoded. insert_op, config. insert_op) ;
2182+ assert_eq ! (
2183+ decoded. keep_partition_by_columns,
2184+ config. keep_partition_by_columns
2185+ ) ;
2186+ assert_eq ! ( decoded. file_extension, config. file_extension) ;
2187+ assert_eq ! ( decoded. file_output_mode, config. file_output_mode) ;
2188+
2189+ let [ decoded_file] = decoded. file_group . files ( ) else {
2190+ panic ! ( "expected one decoded output file" ) ;
2191+ } ;
2192+ let [ config_file] = config. file_group . files ( ) else {
2193+ panic ! ( "expected one configured output file" ) ;
2194+ } ;
2195+ assert_eq ! (
2196+ decoded_file. object_meta. location,
2197+ config_file. object_meta. location
2198+ ) ;
2199+ assert_eq ! ( decoded_file. object_meta. size, config_file. object_meta. size) ;
21732200 Ok ( ( ) )
21742201}
21752202
0 commit comments