@@ -22,7 +22,7 @@ use crate::logical_plan::{
2222} ;
2323use crate :: physical_plan:: {
2424 AsExecutionPlan , DefaultPhysicalExtensionCodec , DefaultPhysicalExtensionProtoCodec ,
25- PhysicalExtensionCodec , PhysicalExtensionProtoCodec ,
25+ PhysicalExtensionCodec , PhysicalProtoConverterExtension ,
2626} ;
2727use crate :: protobuf;
2828use datafusion_common:: { Result , plan_datafusion_err} ;
@@ -90,8 +90,8 @@ pub trait Serializeable: Sized {
9090impl Serializeable for Expr {
9191 fn to_bytes ( & self ) -> Result < Bytes > {
9292 let mut buffer = BytesMut :: new ( ) ;
93- let extension_codec = DefaultLogicalExtensionCodec { } ;
94- let protobuf: protobuf:: LogicalExprNode = serialize_expr ( self , & extension_codec )
93+ let codec = DefaultLogicalExtensionCodec { } ;
94+ let protobuf: protobuf:: LogicalExprNode = serialize_expr ( self , & codec )
9595 . map_err ( |e| plan_datafusion_err ! ( "Error encoding expr as protobuf: {e}" ) ) ?;
9696
9797 protobuf
@@ -192,8 +192,8 @@ impl Serializeable for Expr {
192192 let protobuf = protobuf:: LogicalExprNode :: decode ( bytes)
193193 . map_err ( |e| plan_datafusion_err ! ( "Error decoding expr as protobuf: {e}" ) ) ?;
194194
195- let extension_codec = DefaultLogicalExtensionCodec { } ;
196- logical_plan:: from_proto:: parse_expr ( & protobuf, registry, & extension_codec )
195+ let codec = DefaultLogicalExtensionCodec { } ;
196+ logical_plan:: from_proto:: parse_expr ( & protobuf, registry, & codec )
197197 . map_err ( |e| plan_datafusion_err ! ( "Error parsing protobuf into Expr: {e}" ) )
198198 }
199199}
@@ -277,17 +277,20 @@ pub fn logical_plan_from_json_with_extension_codec(
277277/// Serialize a PhysicalPlan as bytes
278278pub fn physical_plan_to_bytes ( plan : Arc < dyn ExecutionPlan > ) -> Result < Bytes > {
279279 let extension_codec = DefaultPhysicalExtensionCodec { } ;
280- let proto_codec = DefaultPhysicalExtensionProtoCodec { } ;
281- physical_plan_to_bytes_with_extension_codec ( plan, & extension_codec, & proto_codec)
280+ physical_plan_to_bytes_with_extension_codec ( plan, & extension_codec)
282281}
283282
284283/// Serialize a PhysicalPlan as JSON
285284#[ cfg( feature = "json" ) ]
286285pub fn physical_plan_to_json ( plan : Arc < dyn ExecutionPlan > ) -> Result < String > {
287286 let extension_codec = DefaultPhysicalExtensionCodec { } ;
288- let protobuf =
289- protobuf:: PhysicalPlanNode :: try_from_physical_plan ( plan, & extension_codec)
290- . map_err ( |e| plan_datafusion_err ! ( "Error serializing plan: {e}" ) ) ?;
287+ let proto_converter = DefaultPhysicalExtensionProtoCodec { } ;
288+ let protobuf = protobuf:: PhysicalPlanNode :: try_from_physical_plan (
289+ plan,
290+ & extension_codec,
291+ & proto_converter,
292+ )
293+ . map_err ( |e| plan_datafusion_err ! ( "Error serializing plan: {e}" ) ) ?;
291294 serde_json:: to_string ( & protobuf)
292295 . map_err ( |e| plan_datafusion_err ! ( "Error serializing plan: {e}" ) )
293296}
@@ -296,9 +299,19 @@ pub fn physical_plan_to_json(plan: Arc<dyn ExecutionPlan>) -> Result<String> {
296299pub fn physical_plan_to_bytes_with_extension_codec (
297300 plan : Arc < dyn ExecutionPlan > ,
298301 extension_codec : & dyn PhysicalExtensionCodec ,
299- proto_codec : & dyn PhysicalExtensionProtoCodec ,
300302) -> Result < Bytes > {
301- let protobuf = proto_codec. execution_plan_to_proto ( plan, extension_codec) ?;
303+ let proto_conveter = DefaultPhysicalExtensionProtoCodec { } ;
304+ physical_plan_to_bytes_with_proto_converter ( plan, extension_codec, & proto_conveter)
305+ }
306+
307+ /// Serialize a PhysicalPlan as bytes, using the provided extension codec
308+ /// and protobuf converter.
309+ pub fn physical_plan_to_bytes_with_proto_converter (
310+ plan : Arc < dyn ExecutionPlan > ,
311+ extension_codec : & dyn PhysicalExtensionCodec ,
312+ proto_converter : & dyn PhysicalProtoConverterExtension ,
313+ ) -> Result < Bytes > {
314+ let protobuf = proto_converter. execution_plan_to_proto ( & plan, extension_codec) ?;
302315 let mut buffer = BytesMut :: new ( ) ;
303316 protobuf
304317 . encode ( & mut buffer)
@@ -315,7 +328,8 @@ pub fn physical_plan_from_json(
315328 let back: protobuf:: PhysicalPlanNode = serde_json:: from_str ( json)
316329 . map_err ( |e| plan_datafusion_err ! ( "Error serializing plan: {e}" ) ) ?;
317330 let extension_codec = DefaultPhysicalExtensionCodec { } ;
318- back. try_into_physical_plan ( ctx, & extension_codec)
331+ let proto_converter = DefaultPhysicalExtensionProtoCodec { } ;
332+ back. try_into_physical_plan ( ctx, & extension_codec, & proto_converter)
319333}
320334
321335/// Deserialize a PhysicalPlan from bytes
@@ -324,12 +338,12 @@ pub fn physical_plan_from_bytes(
324338 ctx : & TaskContext ,
325339) -> Result < Arc < dyn ExecutionPlan > > {
326340 let extension_codec = DefaultPhysicalExtensionCodec { } ;
327- let proto_codec = DefaultPhysicalExtensionProtoCodec { } ;
328- physical_plan_from_bytes_with_extension_codec (
341+ let proto_converter = DefaultPhysicalExtensionProtoCodec { } ;
342+ physical_plan_from_bytes_with_proto_converter (
329343 bytes,
330344 ctx,
331345 & extension_codec,
332- & proto_codec ,
346+ & proto_converter ,
333347 )
334348}
335349
@@ -338,9 +352,24 @@ pub fn physical_plan_from_bytes_with_extension_codec(
338352 bytes : & [ u8 ] ,
339353 ctx : & TaskContext ,
340354 extension_codec : & dyn PhysicalExtensionCodec ,
341- proto_codec : & dyn PhysicalExtensionProtoCodec ,
355+ ) -> Result < Arc < dyn ExecutionPlan > > {
356+ let proto_converter = DefaultPhysicalExtensionProtoCodec { } ;
357+ physical_plan_from_bytes_with_proto_converter (
358+ bytes,
359+ ctx,
360+ extension_codec,
361+ & proto_converter,
362+ )
363+ }
364+
365+ /// Deserialize a PhysicalPlan from bytes
366+ pub fn physical_plan_from_bytes_with_proto_converter (
367+ bytes : & [ u8 ] ,
368+ ctx : & TaskContext ,
369+ extension_codec : & dyn PhysicalExtensionCodec ,
370+ proto_converter : & dyn PhysicalProtoConverterExtension ,
342371) -> Result < Arc < dyn ExecutionPlan > > {
343372 let protobuf = protobuf:: PhysicalPlanNode :: decode ( bytes)
344373 . map_err ( |e| plan_datafusion_err ! ( "Error decoding expr as protobuf: {e}" ) ) ?;
345- protobuf. try_into_physical_plan ( ctx, extension_codec, proto_codec )
374+ protobuf. try_into_physical_plan ( ctx, extension_codec, proto_converter )
346375}
0 commit comments