From 544e49bb0acac7130a873a92b44e1c902e41ac8f Mon Sep 17 00:00:00 2001 From: Eren Avsarogullari Date: Tue, 2 Apr 2024 06:20:29 -0700 Subject: [PATCH 1/4] Add `spilled_rows` metric to `ExternalSorter` by `IPCWriter` (#9885) * Expose ExternalSorter spilled_rows metric * Issue-9884 - Address review comments --- .../physical-plan/src/metrics/builder.rs | 9 +++++ datafusion/physical-plan/src/metrics/mod.rs | 10 ++++- datafusion/physical-plan/src/metrics/value.rs | 24 ++++++++---- datafusion/physical-plan/src/sorts/sort.rs | 38 +++++++++++++------ 4 files changed, 61 insertions(+), 20 deletions(-) diff --git a/datafusion/physical-plan/src/metrics/builder.rs b/datafusion/physical-plan/src/metrics/builder.rs index 5e8ff72df35c..2037ddb70c2d 100644 --- a/datafusion/physical-plan/src/metrics/builder.rs +++ b/datafusion/physical-plan/src/metrics/builder.rs @@ -123,6 +123,15 @@ impl<'a> MetricBuilder<'a> { count } + /// Consume self and create a new counter for recording the total spilled rows + /// triggered by an operator + pub fn spilled_rows(self, partition: usize) -> Count { + let count = Count::new(); + self.with_partition(partition) + .build(MetricValue::SpilledRows(count.clone())); + count + } + /// Consume self and create a new gauge for reporting current memory usage pub fn mem_used(self, partition: usize) -> Gauge { let gauge = Gauge::new(); diff --git a/datafusion/physical-plan/src/metrics/mod.rs b/datafusion/physical-plan/src/metrics/mod.rs index b2e0086f69e9..9232865aa09c 100644 --- a/datafusion/physical-plan/src/metrics/mod.rs +++ b/datafusion/physical-plan/src/metrics/mod.rs @@ -70,7 +70,7 @@ pub struct Metric { /// The value of the metric value: MetricValue, - /// arbitrary name=value pairs identifiying this metric + /// arbitrary name=value pairs identifying this metric labels: Vec