@@ -11,7 +11,7 @@ use datafusion_proto::{
1111 protobuf:: PhysicalPlanNode ,
1212} ;
1313
14- use crate :: { plan :: DistributedCodec , task:: ExecutionTask } ;
14+ use crate :: task:: ExecutionTask ;
1515
1616use super :: ExecutionStage ;
1717
@@ -35,54 +35,42 @@ pub struct ExecutionStageProto {
3535 pub tasks : Vec < ExecutionTask > ,
3636}
3737
38- impl TryFrom < & ExecutionStage > for ExecutionStageProto {
39- type Error = DataFusionError ;
40-
41- fn try_from ( stage : & ExecutionStage ) -> Result < Self , Self :: Error > {
42- let codec = stage. codec . clone ( ) . unwrap_or ( Arc :: new ( DistributedCodec { } ) ) ;
43-
44- let proto_plan =
45- PhysicalPlanNode :: try_from_physical_plan ( stage. plan . clone ( ) , codec. as_ref ( ) ) ?;
46- let inputs = stage
47- . child_stages_iter ( )
48- . map ( |s| Box :: new ( ExecutionStageProto :: try_from ( s) . unwrap ( ) ) )
49- . collect ( ) ;
50-
51- Ok ( ExecutionStageProto {
52- num : stage. num as u64 ,
53- name : stage. name ( ) ,
54- plan : Some ( Box :: new ( proto_plan) ) ,
55- inputs,
56- tasks : stage. tasks . clone ( ) ,
57- } )
58- }
59- }
60-
61- impl TryFrom < ExecutionStage > for ExecutionStageProto {
62- type Error = DataFusionError ;
38+ pub fn proto_from_stage (
39+ stage : & ExecutionStage ,
40+ codec : & dyn PhysicalExtensionCodec ,
41+ ) -> Result < ExecutionStageProto , DataFusionError > {
42+ let proto_plan = PhysicalPlanNode :: try_from_physical_plan ( stage. plan . clone ( ) , codec) ?;
43+ let inputs = stage
44+ . child_stages_iter ( )
45+ . map ( |s| Ok ( Box :: new ( proto_from_stage ( s, codec) ?) ) )
46+ . collect :: < Result < Vec < _ > > > ( ) ?;
6347
64- fn try_from ( stage : ExecutionStage ) -> Result < Self , Self :: Error > {
65- ExecutionStageProto :: try_from ( & stage)
66- }
48+ Ok ( ExecutionStageProto {
49+ num : stage. num as u64 ,
50+ name : stage. name ( ) ,
51+ plan : Some ( Box :: new ( proto_plan) ) ,
52+ inputs,
53+ tasks : stage. tasks . clone ( ) ,
54+ } )
6755}
6856
6957pub fn stage_from_proto (
7058 msg : ExecutionStageProto ,
7159 registry : & dyn FunctionRegistry ,
7260 runtime : & RuntimeEnv ,
73- codec : Arc < dyn PhysicalExtensionCodec > ,
61+ codec : & dyn PhysicalExtensionCodec ,
7462) -> Result < ExecutionStage > {
7563 let plan_node = msg. plan . ok_or ( internal_datafusion_err ! (
7664 "ExecutionStageMsg is missing the plan"
7765 ) ) ?;
7866
79- let plan = plan_node. try_into_physical_plan ( registry, runtime, codec. as_ref ( ) ) ?;
67+ let plan = plan_node. try_into_physical_plan ( registry, runtime, codec) ?;
8068
8169 let inputs = msg
8270 . inputs
8371 . into_iter ( )
8472 . map ( |s| {
85- stage_from_proto ( * s, registry, runtime, codec. clone ( ) )
73+ stage_from_proto ( * s, registry, runtime, codec)
8674 . map ( |s| Arc :: new ( s) as Arc < dyn ExecutionPlan > )
8775 } )
8876 . collect :: < Result < Vec < _ > > > ( ) ?;
@@ -93,7 +81,6 @@ pub fn stage_from_proto(
9381 plan,
9482 inputs,
9583 tasks : msg. tasks ,
96- codec : Some ( codec) ,
9784 depth : 0 ,
9885 } )
9986}
@@ -116,6 +103,7 @@ mod tests {
116103 use datafusion_proto:: physical_plan:: DefaultPhysicalExtensionCodec ;
117104 use prost:: Message ;
118105
106+ use crate :: stage:: proto:: proto_from_stage;
119107 use crate :: stage:: { proto:: stage_from_proto, ExecutionStage , ExecutionStageProto } ;
120108
121109 // create a simple mem table
@@ -158,12 +146,11 @@ mod tests {
158146 plan : physical_plan,
159147 inputs : vec ! [ ] ,
160148 tasks : vec ! [ ] ,
161- codec : Some ( Arc :: new ( DefaultPhysicalExtensionCodec { } ) ) ,
162149 depth : 0 ,
163150 } ;
164151
165152 // Convert to proto message
166- let stage_msg = ExecutionStageProto :: try_from ( & stage) ?;
153+ let stage_msg = proto_from_stage ( & stage, & DefaultPhysicalExtensionCodec { } ) ?;
167154
168155 // Serialize to bytes
169156 let mut buf = Vec :: new ( ) ;
@@ -180,7 +167,7 @@ mod tests {
180167 decoded_msg,
181168 & ctx,
182169 ctx. runtime_env ( ) . as_ref ( ) ,
183- Arc :: new ( DefaultPhysicalExtensionCodec { } ) ,
170+ & DefaultPhysicalExtensionCodec { } ,
184171 ) ?;
185172
186173 // Compare original and round-tripped stages
0 commit comments