Apache DataFusion SQL Query Engine
Fix Analyze Exec protobuf roundtrip (#17234)
Peter L06547beffb79
diff --git a/datafusion/physical-plan/src/analyze.rs b/datafusion/physical-plan/src/analyze.rsindex ea14ce676c..c095afe5e7 100644--- a/datafusion/physical-plan/src/analyze.rs+++ b/datafusion/physical-plan/src/analyze.rs@@ -134,9 +134,8 @@ impl ExecutionPlan for AnalyzeExec {vec![&self.input]}- /// AnalyzeExec is handled specially so this value is ignoredfn required_input_distribution(&self) -> Vec<Distribution> {- vec![]+ vec![Distribution::UnspecifiedDistribution]}fn with_new_children(diff --git a/datafusion/proto/tests/cases/roundtrip_physical_plan.rs b/datafusion/proto/tests/cases/roundtrip_physical_plan.rsindex 5697a1ff61..1b48dd2a4b 100644--- a/datafusion/proto/tests/cases/roundtrip_physical_plan.rs+++ b/datafusion/proto/tests/cases/roundtrip_physical_plan.rs@@ -1948,3 +1948,40 @@ async fn test_round_trip_date_part_display() -> Result<()> {Ok(())}++#[tokio::test]+/// Tests that we can serialize an unoptimized "analyze" plan and it will work on the other end+async fn analyze_roundtrip_unoptimized() -> Result<()> {+ let ctx = SessionContext::new();++ // No optimizations+ let session_state =+ datafusion::execution::SessionStateBuilder::new_from_existing(ctx.state())+ .with_physical_optimizer_rules(vec![])+ .build();++ let logical_plan = session_state+ .create_logical_plan("explain analyze select 1")+ .await?;+ let plan = session_state.create_physical_plan(&logical_plan).await?;++ let node = PhysicalPlanNode::try_from_physical_plan(+ plan.clone(),+ &DefaultPhysicalExtensionCodec {},+ )?;++ let node = PhysicalPlanNode::decode(node.encode_to_vec().as_slice())+ .map_err(|e| DataFusionError::External(Box::new(e)))?;++ let unoptimized = node.try_into_physical_plan(+ &ctx,+ ctx.runtime_env().as_ref(),+ &DefaultPhysicalExtensionCodec {},+ )?;++ let physical_planner =+ datafusion::physical_planner::DefaultPhysicalPlanner::default();+ physical_planner.optimize_physical_plan(unoptimized, &session_state, |_, _| {})?;++ Ok(())+}