Skip to content

Commit 2eca4c0

Browse files
committed
fix roundtrip_test
1 parent 7dd5e6e commit 2eca4c0

File tree

2 files changed

+23
-1
lines changed

2 files changed

+23
-1
lines changed

datafusion/physical-plan/src/empty.rs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -173,6 +173,16 @@ impl ExecutionPlan for EmptyExec {
173173
None,
174174
))
175175
}
176+
177+
fn with_node_id(
178+
self: Arc<Self>,
179+
_node_id: usize,
180+
) -> Result<Option<Arc<dyn ExecutionPlan>>> {
181+
let mut new_plan = EmptyExec::new(self.schema.clone());
182+
let new_props = new_plan.cache.clone().with_node_id(_node_id);
183+
new_plan.cache = new_props;
184+
Ok(Some(Arc::new(new_plan)))
185+
}
176186
}
177187

178188
#[cfg(test)]

datafusion/proto/tests/cases/roundtrip_physical_plan.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,9 @@ use arrow::csv::WriterBuilder;
3131
use arrow::datatypes::{Fields, TimeUnit};
3232
use datafusion::physical_expr::aggregate::AggregateExprBuilder;
3333
use datafusion::physical_plan::coalesce_batches::CoalesceBatchesExec;
34+
use datafusion::physical_plan::node_id::{
35+
annotate_node_id_for_execution_plan, NodeIdAnnotator,
36+
};
3437
use datafusion_expr::dml::InsertOp;
3538
use datafusion_functions_aggregate::approx_percentile_cont::approx_percentile_cont_udaf;
3639
use datafusion_functions_aggregate::array_agg::array_agg_udaf;
@@ -133,13 +136,22 @@ fn roundtrip_test_and_return(
133136
ctx: &SessionContext,
134137
codec: &dyn PhysicalExtensionCodec,
135138
) -> Result<Arc<dyn ExecutionPlan>> {
139+
let mut annotator = NodeIdAnnotator::new();
140+
let exec_plan = annotate_node_id_for_execution_plan(&exec_plan, &mut annotator)?;
136141
let proto: protobuf::PhysicalPlanNode =
137142
protobuf::PhysicalPlanNode::try_from_physical_plan(exec_plan.clone(), codec)
138143
.expect("to proto");
139144
let runtime = ctx.runtime_env();
140-
let result_exec_plan: Arc<dyn ExecutionPlan> = proto
145+
let mut result_exec_plan: Arc<dyn ExecutionPlan> = proto
141146
.try_into_physical_plan(ctx, runtime.deref(), codec)
142147
.expect("from proto");
148+
149+
// Re-annotate the deserialized plan with node IDs to match the original plan structure
150+
// This ensures that the roundtrip preserves the node_id values for comparison
151+
let mut annotator = NodeIdAnnotator::new();
152+
result_exec_plan =
153+
annotate_node_id_for_execution_plan(&result_exec_plan, &mut annotator)?;
154+
143155
assert_eq!(format!("{exec_plan:?}"), format!("{result_exec_plan:?}"));
144156
Ok(result_exec_plan)
145157
}

0 commit comments

Comments
 (0)