Skip to content

Commit

Permalink
Sort metrics alphabetically in EXPLAIN ANALYZE output
Browse files Browse the repository at this point in the history
  • Loading branch information
progval committed Sep 21, 2024
1 parent 21ec332 commit 7c5238a
Showing 1 changed file with 10 additions and 4 deletions.
14 changes: 10 additions & 4 deletions datafusion/physical-plan/src/metrics/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,8 +301,12 @@ impl MetricsSet {

/// Sort the order of metrics so the "most useful" show up first
pub fn sorted_for_display(mut self) -> Self {
self.metrics
.sort_unstable_by_key(|metric| metric.value().display_sort_key());
self.metrics.sort_unstable_by_key(|metric| {
(
metric.value().display_sort_key(),
metric.value().name().to_owned(),
)
});
self
}

Expand Down Expand Up @@ -665,7 +669,9 @@ mod tests {
MetricBuilder::new(&metrics).end_timestamp(0);
MetricBuilder::new(&metrics).start_timestamp(0);
MetricBuilder::new(&metrics).elapsed_compute(0);
MetricBuilder::new(&metrics).counter("the_second_counter", 0);
MetricBuilder::new(&metrics).counter("the_counter", 0);
MetricBuilder::new(&metrics).counter("the_third_counter", 0);
MetricBuilder::new(&metrics).subset_time("the_time", 0);
MetricBuilder::new(&metrics).output_rows(0);
let metrics = metrics.clone_inner();
Expand All @@ -675,9 +681,9 @@ mod tests {
n.join(", ")
}

assert_eq!("end_timestamp, start_timestamp, elapsed_compute, the_counter, the_time, output_rows", metric_names(&metrics));
assert_eq!("end_timestamp, start_timestamp, elapsed_compute, the_second_counter, the_counter, the_third_counter, the_time, output_rows", metric_names(&metrics));

let metrics = metrics.sorted_for_display();
assert_eq!("output_rows, elapsed_compute, the_counter, the_time, start_timestamp, end_timestamp", metric_names(&metrics));
assert_eq!("output_rows, elapsed_compute, the_counter, the_second_counter, the_third_counter, the_time, start_timestamp, end_timestamp", metric_names(&metrics));
}
}

0 comments on commit 7c5238a

Please sign in to comment.