Skip to content
Prev Previous commit
Next Next commit
feat(metrics): add convert_to_state metric and fix test matcher colli…
…sion

- Added new phase/metric `agg_expr_N_convert_to_state_time`
- Migrated partial-skip path timed separately
- Updated phase configuration
- Regression test triggers partial skip and asserts metric > 0
- Fixed test matcher collision to prevent `state_time` from matching `convert_to_state_time`
  • Loading branch information
kosiew committed Aug 19, 2026
commit 7f1af777ea618292b3794d0a6060a9031a31db29
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,11 @@ use crate::aggregates::{AggregateExec, AggregateMode, aggregate_metric_label};

pub(super) fn accumulator_phases(mode: &AggregateMode) -> &'static [AccumulatorPhase] {
match mode {
AggregateMode::Partial => &[AccumulatorPhase::Update, AccumulatorPhase::State],
AggregateMode::Partial => &[
AccumulatorPhase::Update,
AccumulatorPhase::State,
AccumulatorPhase::ConvertToState,
],
AggregateMode::PartialReduce => {
&[AccumulatorPhase::Merge, AccumulatorPhase::State]
}
Expand Down Expand Up @@ -103,7 +107,11 @@ mod tests {
let cases: [(AggregateMode, &[AccumulatorPhase]); 6] = [
(
AggregateMode::Partial,
&[AccumulatorPhase::Update, AccumulatorPhase::State],
&[
AccumulatorPhase::Update,
AccumulatorPhase::State,
AccumulatorPhase::ConvertToState,
],
),
(
AggregateMode::PartialReduce,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ impl AggregateHashTable<PartialSkipMarker> {
{
output.extend(accumulator_metrics.time(
idx,
AccumulatorPhase::State,
AccumulatorPhase::ConvertToState,
|| acc.convert_to_state(values),
)?);
}
Expand Down
16 changes: 14 additions & 2 deletions datafusion/physical-plan/src/aggregates/group_values/metrics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ pub(crate) enum AccumulatorPhase {
Update,
Merge,
State,
ConvertToState,
Evaluate,
}

Expand All @@ -69,6 +70,7 @@ pub(crate) struct AggregateAccumulatorMetrics {
update_times: Option<Vec<Time>>,
merge_times: Option<Vec<Time>>,
state_times: Option<Vec<Time>>,
convert_to_state_times: Option<Vec<Time>>,
evaluate_times: Option<Vec<Time>>,
}

Expand Down Expand Up @@ -108,6 +110,9 @@ impl AggregateAccumulatorMetrics {
state_times: phases
.contains(&AccumulatorPhase::State)
.then(|| new_phase_metrics("state")),
convert_to_state_times: phases
.contains(&AccumulatorPhase::ConvertToState)
.then(|| new_phase_metrics("convert_to_state")),
evaluate_times: phases
.contains(&AccumulatorPhase::Evaluate)
.then(|| new_phase_metrics("evaluate")),
Expand All @@ -124,6 +129,7 @@ impl AggregateAccumulatorMetrics {
AccumulatorPhase::Update => self.update_times.as_ref(),
AccumulatorPhase::Merge => self.merge_times.as_ref(),
AccumulatorPhase::State => self.state_times.as_ref(),
AccumulatorPhase::ConvertToState => self.convert_to_state_times.as_ref(),
AccumulatorPhase::Evaluate => self.evaluate_times.as_ref(),
};
debug_assert!(
Expand Down Expand Up @@ -209,7 +215,10 @@ mod tests {
.iter()
.filter_map(|metric| match metric.value() {
MetricValue::Time { name, .. }
if name.starts_with("agg_expr_") && name.ends_with(suffix) =>
if name
.strip_prefix("agg_expr_")
.and_then(|name| name.split_once('_'))
.is_some_and(|(_, metric)| metric == suffix) =>
{
let aggregate_label = metric
.labels()
Expand Down Expand Up @@ -243,7 +252,10 @@ mod tests {
matches!(
metric.value(),
MetricValue::Time { name, .. }
if name.starts_with("agg_expr_") && name.ends_with(suffix)
if name
.strip_prefix("agg_expr_")
.and_then(|name| name.split_once('_'))
.is_some_and(|(_, phase)| phase == suffix)
)
}) {
found = true;
Expand Down
1 change: 1 addition & 0 deletions datafusion/physical-plan/src/aggregates/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5656,6 +5656,7 @@ mod tests {
.map(|m| m.as_usize())
.unwrap_or(0);
assert_eq!(skipped_rows, 3);
assert_accumulator_phase_times(&aggregate_exec, &["convert_to_state"]);

Ok(())
}
Expand Down