@@ -3,6 +3,7 @@ use datafusion::arrow::datatypes::SchemaRef;
33use datafusion:: common:: Statistics ;
44use datafusion:: error:: { DataFusionError , Result } ;
55use datafusion:: execution:: { SendableRecordBatchStream , TaskContext } ;
6+ use datafusion:: physical_plan:: metrics:: { BaselineMetrics , ExecutionPlanMetricsSet , MetricsSet } ;
67use datafusion:: physical_plan:: stream:: RecordBatchStreamAdapter ;
78use datafusion:: physical_plan:: {
89 DisplayAs , DisplayFormatType , ExecutionPlan , ExecutionPlanProperties , PlanProperties ,
@@ -24,6 +25,7 @@ pub struct SchemaCastScanExec {
2425 input : Arc < dyn ExecutionPlan > ,
2526 schema : SchemaRef ,
2627 properties : PlanProperties ,
28+ metrics_set : ExecutionPlanMetricsSet ,
2729}
2830
2931impl SchemaCastScanExec {
@@ -41,6 +43,7 @@ impl SchemaCastScanExec {
4143 input,
4244 schema,
4345 properties,
46+ metrics_set : ExecutionPlanMetricsSet :: new ( ) ,
4447 }
4548 }
4649}
@@ -101,14 +104,20 @@ impl ExecutionPlan for SchemaCastScanExec {
101104 ) -> Result < SendableRecordBatchStream > {
102105 let mut stream = self . input . execute ( partition, context) ?;
103106 let schema = Arc :: clone ( & self . schema ) ;
107+ let baseline_metrics = BaselineMetrics :: new ( & self . metrics_set , partition) ;
104108
105109 Ok ( Box :: pin ( RecordBatchStreamAdapter :: new (
106110 Arc :: clone ( & schema) ,
107111 {
108112 stream ! {
109113 while let Some ( batch) = stream. next( ) . await {
114+ let _timer = baseline_metrics. elapsed_compute( ) . timer( ) ;
110115 let batch = record_convert:: try_cast_to( batch?, Arc :: clone( & schema) ) ;
111- yield batch. map_err( |e| { DataFusionError :: External ( Box :: new( e) ) } ) ;
116+ let batch = batch. map_err( |e| { DataFusionError :: External ( Box :: new( e) ) } ) ;
117+ if let Ok ( ref b) = batch {
118+ baseline_metrics. output_rows( ) . add( b. num_rows( ) ) ;
119+ }
120+ yield batch;
112121 }
113122 }
114123 } ,
@@ -118,4 +127,8 @@ impl ExecutionPlan for SchemaCastScanExec {
118127 fn partition_statistics ( & self , partition : Option < usize > ) -> Result < Statistics > {
119128 self . input . partition_statistics ( partition)
120129 }
130+
131+ fn metrics ( & self ) -> Option < MetricsSet > {
132+ Some ( self . metrics_set . clone_inner ( ) )
133+ }
121134}
0 commit comments