@@ -236,6 +236,25 @@ async fn collect_plan_with_categories(
236236 . to_string ( )
237237}
238238
239+ async fn collect_plan_after_set (
240+ ctx : & SessionContext ,
241+ level : & str ,
242+ sql_str : & str ,
243+ ) -> String {
244+ ctx. sql ( & format ! ( "SET datafusion.explain.analyze_level = '{level}'" ) )
245+ . await
246+ . unwrap ( )
247+ . collect ( )
248+ . await
249+ . unwrap ( ) ;
250+
251+ let dataframe = ctx. sql ( sql_str) . await . unwrap ( ) ;
252+ let batches = dataframe. collect ( ) . await . unwrap ( ) ;
253+ arrow:: util:: pretty:: pretty_format_batches ( & batches)
254+ . unwrap ( )
255+ . to_string ( )
256+ }
257+
239258async fn collect_plan ( sql_str : & str , level : MetricType ) -> String {
240259 let ctx = SessionContext :: new ( ) ;
241260 collect_plan_with_context ( sql_str, & ctx, level) . await
@@ -257,6 +276,10 @@ async fn explain_analyze_level() {
257276 ( MetricType :: Dev , "output_rows" , true ) ,
258277 ( MetricType :: Dev , "output_bytes" , true ) ,
259278 ( MetricType :: Dev , "output_batches" , true ) ,
279+ ( MetricType :: Internal , "spill_count" , true ) ,
280+ ( MetricType :: Internal , "output_rows" , true ) ,
281+ ( MetricType :: Internal , "output_bytes" , true ) ,
282+ ( MetricType :: Internal , "output_batches" , true ) ,
260283 ] {
261284 let plan = collect_plan ( sql, level) . await ;
262285 assert_eq ! (
@@ -267,6 +290,33 @@ async fn explain_analyze_level() {
267290 }
268291}
269292
293+ #[ tokio:: test]
294+ async fn explain_analyze_internal_repartition_metrics ( ) {
295+ let ctx = SessionContext :: new_with_config (
296+ SessionConfig :: new ( )
297+ . with_target_partitions ( 4 )
298+ . with_batch_size ( 4096 ) ,
299+ ) ;
300+ register_aggregate_csv_by_sql ( & ctx) . await ;
301+
302+ let sql = "EXPLAIN ANALYZE \
303+ SELECT c1, count(*) \
304+ FROM aggregate_test_100 \
305+ GROUP BY c1";
306+
307+ let dev_plan = collect_plan_after_set ( & ctx, "dev" , sql) . await ;
308+ assert_contains ! ( & dev_plan, "RepartitionExec" ) ;
309+ assert_not_contains ! ( & dev_plan, "hash_compute_time" ) ;
310+ assert_not_contains ! ( & dev_plan, "route_time" ) ;
311+ assert_not_contains ! ( & dev_plan, "batch_build_time" ) ;
312+
313+ let internal_plan = collect_plan_after_set ( & ctx, "internal" , sql) . await ;
314+ assert_contains ! ( & internal_plan, "RepartitionExec" ) ;
315+ assert_contains ! ( & internal_plan, "hash_compute_time" ) ;
316+ assert_contains ! ( & internal_plan, "route_time" ) ;
317+ assert_contains ! ( & internal_plan, "batch_build_time" ) ;
318+ }
319+
270320#[ tokio:: test]
271321async fn explain_analyze_level_datasource_parquet ( ) {
272322 let table_name = "tpch_lineitem_small" ;
@@ -284,6 +334,8 @@ async fn explain_analyze_level_datasource_parquet() {
284334 ( MetricType :: Summary , "page_index_eval_time" , false ) ,
285335 ( MetricType :: Dev , "metadata_load_time" , true ) ,
286336 ( MetricType :: Dev , "page_index_eval_time" , true ) ,
337+ ( MetricType :: Internal , "metadata_load_time" , true ) ,
338+ ( MetricType :: Internal , "page_index_eval_time" , true ) ,
287339 ] {
288340 let plan = collect_plan_with_context ( & sql, & ctx, level) . await ;
289341
0 commit comments