@@ -77,7 +77,7 @@ use datafusion_physical_plan::coop::CooperativeExec;
7777use datafusion_physical_plan:: empty:: EmptyExec ;
7878use datafusion_physical_plan:: explain:: ExplainExec ;
7979use datafusion_physical_plan:: expressions:: PhysicalSortExpr ;
80- use datafusion_physical_plan:: filter:: { FilterExec , FilterExecBuilder } ;
80+ use datafusion_physical_plan:: filter:: FilterExec ;
8181use datafusion_physical_plan:: joins:: utils:: { ColumnIndex , JoinFilter } ;
8282use datafusion_physical_plan:: joins:: {
8383 CrossJoinExec , HashJoinExec , NestedLoopJoinExec , PartitionMode , SortMergeJoinExec ,
@@ -1216,53 +1216,15 @@ pub trait PhysicalPlanNodeExt: Sized {
12161216 ctx : & PhysicalPlanDecodeContext < ' _ > ,
12171217 proto_converter : & dyn PhysicalProtoConverterExtension ,
12181218 ) -> Result < Arc < dyn ExecutionPlan > > {
1219- let input: Arc < dyn ExecutionPlan > =
1220- into_physical_plan ( & filter. input , ctx, proto_converter) ?;
1221-
1222- let predicate = filter
1223- . expr
1224- . as_ref ( )
1225- . map ( |expr| {
1226- proto_converter. proto_to_physical_expr ( expr, input. schema ( ) . as_ref ( ) , ctx)
1227- } )
1228- . transpose ( ) ?
1229- . ok_or_else ( || {
1230- internal_datafusion_err ! (
1231- "filter (FilterExecNode) in PhysicalPlanNode is missing."
1232- )
1233- } ) ?;
1234-
1235- let filter_selectivity = filter. default_filter_selectivity . try_into ( ) ;
1236- // Preserve the `None` state across proto boundaries. Proto cannot distinguish
1237- // between `None` (full projection) and `Some(vec![])` (empty projection) since
1238- // both serialize as an empty list. If all columns are included, we reconstruct
1239- // `None` to avoid losing this semantic distinction on deserialization.
1240- let num_fields = input. schema ( ) . fields ( ) . len ( ) ;
1241- let mut is_full_projection = filter. projection . len ( ) == num_fields;
1242- let mut projection_vec: Vec < usize > = Vec :: with_capacity ( filter. projection . len ( ) ) ;
1243- for ( i, idx) in filter. projection . iter ( ) . enumerate ( ) {
1244- let idx = * idx as usize ;
1245- is_full_projection &= idx == i;
1246- projection_vec. push ( idx) ;
1247- }
1248- let projection = if is_full_projection {
1249- None
1250- } else {
1251- Some ( projection_vec)
1219+ let node = protobuf:: PhysicalPlanNode {
1220+ physical_plan_type : Some ( PhysicalPlanType :: Filter ( Box :: new ( filter. clone ( ) ) ) ) ,
12521221 } ;
1253- let filter = FilterExecBuilder :: new ( predicate, input)
1254- . apply_projection ( projection) ?
1255- . with_batch_size ( filter. batch_size as usize )
1256- . with_fetch ( filter. fetch . map ( |f| f as usize ) )
1257- . build ( ) ?;
1258- match filter_selectivity {
1259- Ok ( filter_selectivity) => Ok ( Arc :: new (
1260- filter. with_default_selectivity ( filter_selectivity) ?,
1261- ) ) ,
1262- Err ( _) => Err ( internal_datafusion_err ! (
1263- "filter_selectivity in PhysicalPlanNode is invalid "
1264- ) ) ,
1265- }
1222+ let decoder = ConverterPlanDecoder {
1223+ ctx,
1224+ proto_converter,
1225+ } ;
1226+ let decode_ctx = ExecutionPlanDecodeCtx :: new ( & decoder) ;
1227+ FilterExec :: try_from_proto ( & node, & decode_ctx)
12661228 }
12671229
12681230 fn try_into_csv_scan_physical_plan (
@@ -2968,31 +2930,13 @@ pub trait PhysicalPlanNodeExt: Sized {
29682930 codec : & dyn PhysicalExtensionCodec ,
29692931 proto_converter : & dyn PhysicalProtoConverterExtension ,
29702932 ) -> Result < protobuf:: PhysicalPlanNode > {
2971- let input = protobuf:: PhysicalPlanNode :: try_from_physical_plan_with_converter (
2972- exec. input ( ) . to_owned ( ) ,
2933+ let encoder = ConverterPlanEncoder {
29732934 codec,
29742935 proto_converter,
2975- ) ?;
2976- Ok ( protobuf:: PhysicalPlanNode {
2977- physical_plan_type : Some ( PhysicalPlanType :: Filter ( Box :: new (
2978- protobuf:: FilterExecNode {
2979- input : Some ( Box :: new ( input) ) ,
2980- expr : Some (
2981- proto_converter
2982- . physical_expr_to_proto ( exec. predicate ( ) , codec) ?,
2983- ) ,
2984- default_filter_selectivity : exec. default_selectivity ( ) as u32 ,
2985- projection : match exec. projection ( ) {
2986- None => ( 0 ..exec. input ( ) . schema ( ) . fields ( ) . len ( ) )
2987- . map ( |i| i as u32 )
2988- . collect ( ) ,
2989- Some ( v) => v. iter ( ) . map ( |x| * x as u32 ) . collect ( ) ,
2990- } ,
2991- batch_size : exec. batch_size ( ) as u32 ,
2992- fetch : exec. fetch ( ) . map ( |f| f as u32 ) ,
2993- } ,
2994- ) ) ) ,
2995- } )
2936+ } ;
2937+ let encode_ctx = ExecutionPlanEncodeCtx :: new ( & encoder) ;
2938+ exec. try_to_proto ( & encode_ctx) ?
2939+ . ok_or_else ( || internal_datafusion_err ! ( "FilterExec is not serializable" ) )
29962940 }
29972941
29982942 fn try_from_global_limit_exec (
0 commit comments