|
1 | 1 | use crate::display_plan_ascii; |
2 | 2 | use crate::execution_plans::DistributedExec; |
3 | | -use crate::metrics::MetricsCollectorResult; |
4 | | -use crate::metrics::TaskMetricsCollector; |
5 | | -use crate::metrics::proto::MetricsSetProto; |
6 | | -use crate::metrics::proto::df_metrics_set_to_proto; |
7 | | -use crate::stage::DisplayCtx; |
| 3 | +use crate::metrics::rewrite_distributed_plan_with_metrics; |
8 | 4 | use datafusion::error::DataFusionError; |
9 | 5 | use datafusion::physical_plan::ExecutionPlan; |
10 | 6 | use datafusion::physical_plan::display::DisplayableExecutionPlan; |
11 | 7 | use std::sync::Arc; |
12 | 8 |
|
13 | 9 | /// explain_analyze renders an [ExecutionPlan] with metrics. |
14 | 10 | pub fn explain_analyze(executed: Arc<dyn ExecutionPlan>) -> Result<String, DataFusionError> { |
15 | | - // Check if the plan is distributed by looking for a root DistributedExec. |
16 | 11 | match executed.as_any().downcast_ref::<DistributedExec>() { |
17 | 12 | None => Ok(DisplayableExecutionPlan::with_metrics(executed.as_ref()) |
18 | 13 | .indent(true) |
19 | 14 | .to_string()), |
20 | | - Some(dist_exec) => { |
21 | | - // If the plan was distributed, collect metrics from the coordinating stage exec. |
22 | | - // TODO: Should we move this into the DistributedExec itself or a new ExplainAnalyzeExec? |
23 | | - let MetricsCollectorResult { |
24 | | - task_metrics, |
25 | | - mut input_task_metrics, |
26 | | - } = TaskMetricsCollector::new().collect(dist_exec.pepared_plan()?)?; |
27 | | - |
28 | | - input_task_metrics.insert( |
29 | | - dist_exec.to_stage_key(), |
30 | | - task_metrics |
31 | | - .into_iter() |
32 | | - .map(|metrics| df_metrics_set_to_proto(&metrics)) |
33 | | - .collect::<Result<Vec<MetricsSetProto>, DataFusionError>>()?, |
34 | | - ); |
35 | | - |
36 | | - let display_ctx = DisplayCtx::new(input_task_metrics); |
37 | | - Ok(display_plan_ascii(&dist_exec.with_display_ctx(display_ctx))) |
| 15 | + Some(_) => { |
| 16 | + let executed = rewrite_distributed_plan_with_metrics(executed.clone())?; |
| 17 | + Ok(display_plan_ascii(executed.as_ref())) |
38 | 18 | } |
39 | 19 | } |
40 | 20 | } |
0 commit comments