@@ -4,7 +4,10 @@ use crate::metrics::MetricsCollectorResult;
44use crate :: metrics:: TaskMetricsCollector ;
55use crate :: metrics:: proto:: MetricsSetProto ;
66use crate :: metrics:: proto:: df_metrics_set_to_proto;
7+ use crate :: metrics:: rewrite_distributed_plan_with_metrics;
8+ use crate :: protobuf:: StageKey ;
79use crate :: stage:: DisplayCtx ;
10+ use bytes:: Bytes ;
811use datafusion:: error:: DataFusionError ;
912use datafusion:: physical_plan:: ExecutionPlan ;
1013use datafusion:: physical_plan:: display:: DisplayableExecutionPlan ;
@@ -25,15 +28,28 @@ pub fn explain_analyze(executed: Arc<dyn ExecutionPlan>) -> Result<String, DataF
2528 mut input_task_metrics,
2629 } = TaskMetricsCollector :: new ( ) . collect ( dist_exec. pepared_plan ( ) ?) ?;
2730
31+ // let input_stage = dist_exec.pepared_plan()?
32+ let fake_stage = dist_exec. synthetic_stage ( ) ;
33+ let stage_key = StageKey {
34+ query_id : Bytes :: from ( fake_stage. query_id . as_bytes ( ) . to_vec ( ) ) ,
35+ stage_id : fake_stage. num as u64 ,
36+ task_number : 0 ,
37+ } ;
2838 input_task_metrics. insert (
29- dist_exec . to_stage_key ( ) ,
39+ stage_key ,
3040 task_metrics
3141 . into_iter ( )
3242 . map ( |metrics| df_metrics_set_to_proto ( & metrics) )
3343 . collect :: < Result < Vec < MetricsSetProto > , DataFusionError > > ( ) ?,
3444 ) ;
3545
36- let display_ctx = DisplayCtx :: new ( input_task_metrics) ;
46+ let executed = rewrite_distributed_plan_with_metrics (
47+ executed. clone ( ) ,
48+ Arc :: new ( input_task_metrics) ,
49+ ) ?;
50+ let dist_exec = executed. as_any ( ) . downcast_ref :: < DistributedExec > ( ) . unwrap ( ) ;
51+
52+ let display_ctx = DisplayCtx :: new ( ) . with_metrics ( ) ;
3753 Ok ( display_plan_ascii ( & dist_exec. with_display_ctx ( display_ctx) ) )
3854 }
3955 }
0 commit comments