@@ -33,13 +33,27 @@ pub enum DisplayFormatType {
3333/// Wraps an `ExecutionPlan` with various ways to display this plan
3434pub struct DisplayableExecutionPlan < ' a > {
3535 inner : & ' a dyn ExecutionPlan ,
36+ /// whether to show metrics or not
37+ with_metrics : bool ,
3638}
3739
3840impl < ' a > DisplayableExecutionPlan < ' a > {
3941 /// Create a wrapper around an [`'ExecutionPlan'] which can be
4042 /// pretty printed in a variety of ways
4143 pub fn new ( inner : & ' a dyn ExecutionPlan ) -> Self {
42- Self { inner }
44+ Self {
45+ inner,
46+ with_metrics : false ,
47+ }
48+ }
49+
50+ /// Create a wrapper around an [`'ExecutionPlan'] which can be
51+ /// pretty printed in a variety of ways
52+ pub fn with_metrics ( inner : & ' a dyn ExecutionPlan ) -> Self {
53+ Self {
54+ inner,
55+ with_metrics : true ,
56+ }
4357 }
4458
4559 /// Return a `format`able structure that produces a single line
@@ -53,15 +67,26 @@ impl<'a> DisplayableExecutionPlan<'a> {
5367 /// CsvExec: source=...",
5468 /// ```
5569 pub fn indent ( & self ) -> impl fmt:: Display + ' a {
56- struct Wrapper < ' a > ( & ' a dyn ExecutionPlan ) ;
70+ struct Wrapper < ' a > {
71+ plan : & ' a dyn ExecutionPlan ,
72+ with_metrics : bool ,
73+ }
5774 impl < ' a > fmt:: Display for Wrapper < ' a > {
5875 fn fmt ( & self , f : & mut fmt:: Formatter ) -> fmt:: Result {
5976 let t = DisplayFormatType :: Default ;
60- let mut visitor = IndentVisitor { t, f, indent : 0 } ;
61- accept ( self . 0 , & mut visitor)
77+ let mut visitor = IndentVisitor {
78+ t,
79+ f,
80+ indent : 0 ,
81+ with_metrics : self . with_metrics ,
82+ } ;
83+ accept ( self . plan , & mut visitor)
6284 }
6385 }
64- Wrapper ( self . inner )
86+ Wrapper {
87+ plan : self . inner ,
88+ with_metrics : self . with_metrics ,
89+ }
6590 }
6691}
6792
@@ -71,8 +96,10 @@ struct IndentVisitor<'a, 'b> {
7196 t : DisplayFormatType ,
7297 /// Write to this formatter
7398 f : & ' a mut fmt:: Formatter < ' b > ,
74- ///with_schema: bool,
99+ /// Indent size
75100 indent : usize ,
101+ /// whether to show metrics or not
102+ with_metrics : bool ,
76103}
77104
78105impl < ' a , ' b > ExecutionPlanVisitor for IndentVisitor < ' a , ' b > {
@@ -83,6 +110,17 @@ impl<'a, 'b> ExecutionPlanVisitor for IndentVisitor<'a, 'b> {
83110 ) -> std:: result:: Result < bool , Self :: Error > {
84111 write ! ( self . f, "{:indent$}" , "" , indent = self . indent * 2 ) ?;
85112 plan. fmt_as ( self . t , self . f ) ?;
113+ if self . with_metrics {
114+ write ! (
115+ self . f,
116+ ", metrics=[{}]" ,
117+ plan. metrics( )
118+ . iter( )
119+ . map( |( k, v) | format!( "{}={:?}" , k, v. value) )
120+ . collect:: <Vec <_>>( )
121+ . join( ", " )
122+ ) ?;
123+ }
86124 writeln ! ( self . f) ?;
87125 self . indent += 1 ;
88126 Ok ( true )
0 commit comments