Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
33 changes: 17 additions & 16 deletions native/core/src/execution/metrics/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,6 @@ pub(crate) fn update_comet_metric(
pub(crate) fn to_native_metric_node(
spark_plan: &Arc<SparkPlan>,
) -> Result<NativeMetricNode, CometError> {
let mut native_metric_node = NativeMetricNode {
metrics: HashMap::new(),
children: Vec::new(),
};

let node_metrics = if spark_plan.additional_native_plans.is_empty() {
spark_plan.native_plan.metrics()
} else {
Expand All @@ -68,18 +63,24 @@ pub(crate) fn to_native_metric_node(
Some(metrics.aggregate_by_name())
};

// add metrics
node_metrics
.unwrap_or_default()
.iter()
.map(|m| m.value())
.map(|m| (m.name(), m.as_usize() as i64))
.for_each(|(name, value)| {
native_metric_node.metrics.insert(name.to_string(), value);
});
let children = spark_plan.children();
let mut native_metric_node = NativeMetricNode {
// Most operator metric maps are well under 20 entries (e.g. hash-join: 9,
// native-scan: ~20). Pre-sizing to 16 avoids the default-capacity rehash.
metrics: HashMap::with_capacity(16),
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: use a constant for readability?

children: Vec::with_capacity(children.len()),
};

if let Some(metrics) = node_metrics {
for m in metrics.iter() {
let value = m.value();
native_metric_node
.metrics
.insert(value.name().to_string(), value.as_usize() as i64);
}
}

// add children
for child_plan in spark_plan.children() {
for child_plan in children {
let child_node = to_native_metric_node(child_plan)?;
native_metric_node.children.push(child_node);
}
Expand Down
Loading