1616// under the License.
1717
1818use datafusion:: physical_plan:: { displayable, ExecutionPlan , ExecutionPlanProperties } ;
19- use datafusion_proto:: physical_plan:: { AsExecutionPlan , DefaultPhysicalExtensionCodec } ;
19+ use datafusion_proto:: physical_plan:: { AsExecutionPlan , PhysicalExtensionCodec } ;
20+ use deltalake:: delta_datafusion:: DeltaPhysicalCodec ;
2021use prost:: Message ;
21- use std:: sync:: Arc ;
22-
2322use pyo3:: { exceptions:: PyRuntimeError , prelude:: * , types:: PyBytes } ;
23+ use std:: sync:: Arc ;
2424
2525use crate :: { context:: PySessionContext , errors:: PyDataFusionResult } ;
2626
@@ -59,10 +59,9 @@ impl PyExecutionPlan {
5959 }
6060
6161 pub fn to_proto < ' py > ( & ' py self , py : Python < ' py > ) -> PyDataFusionResult < Bound < ' py , PyBytes > > {
62- let codec = DefaultPhysicalExtensionCodec { } ;
6362 let proto = datafusion_proto:: protobuf:: PhysicalPlanNode :: try_from_physical_plan (
6463 self . plan . clone ( ) ,
65- & codec,
64+ codec ( ) ,
6665 ) ?;
6766
6867 let bytes = proto. encode_to_vec ( ) ;
@@ -83,8 +82,7 @@ impl PyExecutionPlan {
8382 ) )
8483 } ) ?;
8584
86- let codec = DefaultPhysicalExtensionCodec { } ;
87- let plan = proto_plan. try_into_physical_plan ( & ctx. ctx , & ctx. ctx . runtime_env ( ) , & codec) ?;
85+ let plan = proto_plan. try_into_physical_plan ( & ctx. ctx , & ctx. ctx . runtime_env ( ) , codec ( ) ) ?;
8886 Ok ( Self :: new ( plan) )
8987 }
9088
@@ -109,3 +107,8 @@ impl From<Arc<dyn ExecutionPlan>> for PyExecutionPlan {
109107 PyExecutionPlan { plan : plan. clone ( ) }
110108 }
111109}
110+
111+ pub ( crate ) fn codec ( ) -> & ' static dyn PhysicalExtensionCodec {
112+ static CODEC : DeltaPhysicalCodec = DeltaPhysicalCodec { } ;
113+ & CODEC
114+ }
0 commit comments