Skip to content

Fix metrics for repartition when preserve_order=true - #20924

Merged
alamb merged 3 commits into
apache:mainfrom
xanderbailey:xb/fix-repartition-preserve-order-metrics-double-count
Jun 30, 2026
Merged

Fix metrics for repartition when preserve_order=true#20924
alamb merged 3 commits into
apache:mainfrom
xanderbailey:xb/fix-repartition-preserve-order-metrics-double-count

Conversation

@xanderbailey

@xanderbaileyxanderbailey commented Mar 13, 2026

Copy link
Copy Markdown
Contributor

Which issue does this PR close?

Found this when working on #20875

  • Closes #.

Rationale for this change

Metric reporting was previously incorrect for RepartitionExec if preserve order was set to true.

What changes are included in this PR?

Create new metrics before creating PerPartitionStream

Are these changes tested?

Yes and confirmed that this fails on main:

 thread 'repartition::test::test_preserve_order_output_rows_not_double_counted' (12487869)
panicked at datafusion/physical-plan/src/repartition/mod.rs:3007:9:
assertion `left == right` failed: metrics output_rows (8) should match actual rows
collected (4), not double-count
left: 8
right: 4
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

Are there any user-facing changes?

@xanderbailey
xanderbaileyforce-pushed the xb/fix-repartition-preserve-order-metrics-double-count branch from 5a7328a to a5ccd80CompareMarch 13, 2026 12:05
@github-actionsgithub-actionsBot added the physical-plan Changes to the physical-plan crate label Mar 13, 2026
@xanderbailey
xanderbaileyforce-pushed the xb/fix-repartition-preserve-order-metrics-double-count branch from a5ccd80 to 01598d9CompareMarch 13, 2026 13:22

@alambalamb left a comment

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.

spill_stream,
1, // Each receiver handles one input partition
BaselineMetrics::new(&metrics, partition),
BaselineMetrics::new(&intermediate_metrics, partition),

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.

if we are just going to ignore the metrics, should we just remove them from PerPartitionStream ?

It seems like using a local copy of ExecutionPlanMetrics means they metrics in the PerPartitionStream are no longer accessable. So we can probably just remove the metrics to make it clearer they aren't used

@xanderbaileyxanderbaileyMar 13, 2026

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Yeah good question, we still use PerPartitionStream here

Ok(Box::pin(PerPartitionStream::new(
. We can make the metrics optional which is maybe more explicit?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Any thoughts here on what you'd prefer @alamb?

Copy link
Copy Markdown
ContributorAuthor

Choose a reason for hiding this comment

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

Making it optional made the code inside PerPartitionStream less clean I think but I don't have a strong opinion I have to say so I'm happy to do whatever

@xanderbailey

Copy link
Copy Markdown
ContributorAuthor

@alamb I made the metrics optional in 6ee4c22 let me know if you think that works?

@github-actions

Copy link
Copy Markdown

Thank you for your contribution. Unfortunately, this pull request is stale because it has been open 60 days with no activity. Please remove the stale label or comment or this will be closed in 7 days.

@github-actionsgithub-actionsBot added the Stale PR has not had any activity for some time label Jun 28, 2026
@xanderbailey

Copy link
Copy Markdown
ContributorAuthor

Not stale please don’t close

@xanderbailey

Copy link
Copy Markdown
ContributorAuthor

I’m away for a week or so and I’ll resolve the conflict then but I’d love to get the one merged if we can

@github-actionsgithub-actionsBot removed the Stale PR has not had any activity for some time label Jun 29, 2026

@alambalamb left a comment

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.

Thanks @xanderbailey -- this looks good to me


/// preserve_order repartition should not double-count
/// output rows.
#[tokio::test]

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.

I verified this test covers the new code


cargo test -p datafusion-physical-plan -- --nocapture

This fails without the code change

 thread 'repartition::test::test_preserve_order_output_rows_not_double_counted' panicked at datafusion/physical-plan/src/repartition/mod.rs:2991:9:
assertion `left == right` failed: metrics output_rows (8) should match actual rows collected (4), not double-count
left: 8
right: 4
Verification

@alambalamb changed the title Fix metrics for repartitionFix metrics for repartition when preserve_order=trueJun 29, 2026
@alamb
alamb added this pull request to the merge queueJun 30, 2026
@github-merge-queue
github-merge-queueBot removed this pull request from the merge queue due to failed status checks Jun 30, 2026
@xanderbailey

Copy link
Copy Markdown
ContributorAuthor

Looks like a CI flake, are you able to re-trigger @alamb?

@alamb
alamb added this pull request to the merge queueJun 30, 2026
@alamb

Copy link
Copy Markdown
Contributor

Thanks @xanderbailey

Merged via the queue into apache:main with commit d302350Jun 30, 2026
38 checks passed
@alamb

Copy link
Copy Markdown
Contributor

Thanks again @xanderbailey

Sign up for freeto join this conversation on GitHub. Already have an account? Sign in to comment

Labels

physical-planChanges to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants

@xanderbailey@alamb