1616// under the License.
1717
1818use datafusion_physical_plan:: metrics:: {
19- Count , ExecutionPlanMetricsSet , Gauge , MetricBuilder , MetricCategory , MetricType ,
20- PruningMetrics , RatioMergeStrategy , RatioMetrics , Time ,
19+ Count , ExecutionPlanMetricsSet , Gauge , Label , MetricBuilder , MetricCategory ,
20+ MetricType , PruningMetrics , RatioMergeStrategy , RatioMetrics , Time ,
2121} ;
2222
2323/// Stores metrics about the parquet execution for a particular parquet file.
@@ -100,46 +100,51 @@ impl ParquetFileMetrics {
100100 filename : & str ,
101101 metrics : & ExecutionPlanMetricsSet ,
102102 ) -> Self {
103+ // Share the filename label across all per-file metrics to avoid
104+ // allocating the same filename string for each metric.
105+ let filename_label = Label :: new ( "filename" , filename. to_string ( ) ) ;
106+ let builder = MetricBuilder :: new ( metrics) . with_label ( filename_label) ;
107+
103108 // -----------------------
104109 // 'summary' level metrics
105110 // -----------------------
106- let row_groups_pruned_bloom_filter = MetricBuilder :: new ( metrics )
107- . with_new_label ( "filename" , filename . to_string ( ) )
111+ let row_groups_pruned_bloom_filter = builder
112+ . clone ( )
108113 . with_type ( MetricType :: Summary )
109114 . pruning_metrics ( "row_groups_pruned_bloom_filter" , partition) ;
110115
111- let limit_pruned_row_groups = MetricBuilder :: new ( metrics )
112- . with_new_label ( "filename" , filename . to_string ( ) )
116+ let limit_pruned_row_groups = builder
117+ . clone ( )
113118 . with_type ( MetricType :: Summary )
114119 . pruning_metrics ( "limit_pruned_row_groups" , partition) ;
115120
116- let row_groups_pruned_statistics = MetricBuilder :: new ( metrics )
117- . with_new_label ( "filename" , filename . to_string ( ) )
121+ let row_groups_pruned_statistics = builder
122+ . clone ( )
118123 . with_type ( MetricType :: Summary )
119124 . pruning_metrics ( "row_groups_pruned_statistics" , partition) ;
120125
121- let page_index_pages_pruned = MetricBuilder :: new ( metrics )
122- . with_new_label ( "filename" , filename . to_string ( ) )
126+ let page_index_pages_pruned = builder
127+ . clone ( )
123128 . with_type ( MetricType :: Summary )
124129 . pruning_metrics ( "page_index_pages_pruned" , partition) ;
125130
126- let bytes_scanned = MetricBuilder :: new ( metrics )
127- . with_new_label ( "filename" , filename . to_string ( ) )
131+ let bytes_scanned = builder
132+ . clone ( )
128133 . with_type ( MetricType :: Summary )
129134 . with_category ( MetricCategory :: Bytes )
130135 . counter ( "bytes_scanned" , partition) ;
131136
132- let metadata_load_time = MetricBuilder :: new ( metrics )
133- . with_new_label ( "filename" , filename . to_string ( ) )
137+ let metadata_load_time = builder
138+ . clone ( )
134139 . with_type ( MetricType :: Summary )
135140 . subset_time ( "metadata_load_time" , partition) ;
136141
137142 let files_ranges_pruned_statistics = MetricBuilder :: new ( metrics)
138143 . with_type ( MetricType :: Summary )
139144 . pruning_metrics ( "files_ranges_pruned_statistics" , partition) ;
140145
141- let scan_efficiency_ratio = MetricBuilder :: new ( metrics )
142- . with_new_label ( "filename" , filename . to_string ( ) )
146+ let scan_efficiency_ratio = builder
147+ . clone ( )
143148 . with_type ( MetricType :: Summary )
144149 . ratio_metrics_with_strategy (
145150 "scan_efficiency_ratio" ,
@@ -150,45 +155,44 @@ impl ParquetFileMetrics {
150155 // -----------------------
151156 // 'dev' level metrics
152157 // -----------------------
153- let predicate_evaluation_errors = MetricBuilder :: new ( metrics )
154- . with_new_label ( "filename" , filename . to_string ( ) )
158+ let predicate_evaluation_errors = builder
159+ . clone ( )
155160 . with_category ( MetricCategory :: Rows )
156161 . counter ( "predicate_evaluation_errors" , partition) ;
157162
158- let pushdown_rows_pruned = MetricBuilder :: new ( metrics )
159- . with_new_label ( "filename" , filename . to_string ( ) )
163+ let pushdown_rows_pruned = builder
164+ . clone ( )
160165 . with_category ( MetricCategory :: Rows )
161166 . counter ( "pushdown_rows_pruned" , partition) ;
162- let pushdown_rows_matched = MetricBuilder :: new ( metrics )
163- . with_new_label ( "filename" , filename . to_string ( ) )
167+ let pushdown_rows_matched = builder
168+ . clone ( )
164169 . with_category ( MetricCategory :: Rows )
165170 . counter ( "pushdown_rows_matched" , partition) ;
166171
167- let row_pushdown_eval_time = MetricBuilder :: new ( metrics )
168- . with_new_label ( "filename" , filename . to_string ( ) )
172+ let row_pushdown_eval_time = builder
173+ . clone ( )
169174 . subset_time ( "row_pushdown_eval_time" , partition) ;
170- let statistics_eval_time = MetricBuilder :: new ( metrics )
171- . with_new_label ( "filename" , filename . to_string ( ) )
175+ let statistics_eval_time = builder
176+ . clone ( )
172177 . subset_time ( "statistics_eval_time" , partition) ;
173- let bloom_filter_eval_time = MetricBuilder :: new ( metrics )
174- . with_new_label ( "filename" , filename . to_string ( ) )
178+ let bloom_filter_eval_time = builder
179+ . clone ( )
175180 . subset_time ( "bloom_filter_eval_time" , partition) ;
176181
177- let page_index_eval_time = MetricBuilder :: new ( metrics )
178- . with_new_label ( "filename" , filename . to_string ( ) )
182+ let page_index_eval_time = builder
183+ . clone ( )
179184 . subset_time ( "page_index_eval_time" , partition) ;
180185
181- let page_index_rows_pruned = MetricBuilder :: new ( metrics )
182- . with_new_label ( "filename" , filename . to_string ( ) )
186+ let page_index_rows_pruned = builder
187+ . clone ( )
183188 . pruning_metrics ( "page_index_rows_pruned" , partition) ;
184189
185- let predicate_cache_inner_records = MetricBuilder :: new ( metrics )
186- . with_new_label ( "filename" , filename . to_string ( ) )
190+ let predicate_cache_inner_records = builder
191+ . clone ( )
187192 . with_category ( MetricCategory :: Rows )
188193 . gauge ( "predicate_cache_inner_records" , partition) ;
189194
190- let predicate_cache_records = MetricBuilder :: new ( metrics)
191- . with_new_label ( "filename" , filename. to_string ( ) )
195+ let predicate_cache_records = builder
192196 . with_category ( MetricCategory :: Rows )
193197 . gauge ( "predicate_cache_records" , partition) ;
194198
0 commit comments