Skip to content

Commit 89218ba

Browse files
committed
Improve ergonomics for ExecutionPlanMetricsSet and MetricsSet
1 parent a737c27 commit 89218ba

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

  • datafusion/physical-expr-common/src/metrics

datafusion/physical-expr-common/src/metrics/mod.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ mod value;
2626
use datafusion_common::HashMap;
2727
pub use datafusion_common::format::{MetricCategory, MetricType};
2828
use parking_lot::Mutex;
29+
use std::vec::IntoIter;
2930
use std::{
3031
borrow::Cow,
3132
fmt::{self, Debug, Display},
@@ -225,6 +226,11 @@ impl MetricsSet {
225226
self.metrics.push(metric)
226227
}
227228

229+
/// Extends the current list of metrics with the provided ones
230+
pub fn extend(&mut self, metrics: impl Iterator<Item = Arc<Metric>>) {
231+
self.metrics.extend(metrics)
232+
}
233+
228234
/// Returns an iterator across all metrics
229235
pub fn iter(&self) -> impl Iterator<Item = &Arc<Metric>> {
230236
self.metrics.iter()
@@ -432,6 +438,15 @@ impl Display for MetricsSet {
432438
}
433439
}
434440

441+
impl IntoIterator for MetricsSet {
442+
type Item = Arc<Metric>;
443+
type IntoIter = IntoIter<Self::Item>;
444+
445+
fn into_iter(self) -> Self::IntoIter {
446+
self.metrics.into_iter()
447+
}
448+
}
449+
435450
/// A set of [`Metric`]s for an individual operator.
436451
///
437452
/// This structure is intended as a convenience for execution plan
@@ -465,6 +480,14 @@ impl ExecutionPlanMetricsSet {
465480
}
466481
}
467482

483+
impl From<MetricsSet> for ExecutionPlanMetricsSet {
484+
fn from(metrics: MetricsSet) -> Self {
485+
Self {
486+
inner: Arc::new(Mutex::new(metrics)),
487+
}
488+
}
489+
}
490+
468491
/// `name=value` pairs identifying a metric. This concept is called various things
469492
/// in various different systems:
470493
///

0 commit comments

Comments
 (0)