Skip to content

chore: simplify SortPreservingMergeStream to be as textbook-like as possible#23702

Open
rluvaton wants to merge 6 commits into
apache:mainfrom
rluvaton:simplify-sort-preserving-merge-stream
Open

chore: simplify SortPreservingMergeStream to be as textbook-like as possible#23702
rluvaton wants to merge 6 commits into
apache:mainfrom
rluvaton:simplify-sort-preserving-merge-stream

Conversation

@rluvaton

Copy link
Copy Markdown
Member

Which issue does this PR close?

N/A

Rationale for this change

SortPreservingMergeStream is a little complex, so add some guiding comments and make it as textbook-like as possible

What changes are included in this PR?

Added comments, reorder code

Are these changes tested?

Existing tests

Are there any user-facing changes?

No

@github-actions github-actions Bot added the physical-plan Changes to the physical-plan crate label Jul 19, 2026
@rluvaton
rluvaton marked this pull request as ready for review July 19, 2026 16:02
Comment on lines +298 to +313
let should_poll_next_batch_for_stream =
self.advance_cursors(winner_stream);

// Fast path: skip the `maybe_poll_stream` call (and its `Poll`
// plumbing) unless the winner's cursor is exhausted and needs a
// fresh batch — it is live for almost every row.
if should_poll_next_batch_for_stream {
assert!(
self.cursors[winner_stream].is_none(),
"cursor should be exhausted"
);

drop(timer);
poll_fn(|cx| self.maybe_poll_stream(cx, winner_stream)).await?;
timer = elapsed_compute.timer();
}

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

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

I wanted to move the poll stream inside the advance_cursors but got lifetime issues so kept like this

@codecov-commenter

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 88.70968% with 7 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.67%. Comparing base (67947b6) to head (7175283).

Files with missing lines Patch % Lines
datafusion/physical-plan/src/sorts/merge.rs 90.56% 2 Missing and 3 partials ⚠️
...afusion/physical-plan/src/sorts/streaming_merge.rs 77.77% 2 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##             main   #23702      +/-   ##
==========================================
- Coverage   80.67%   80.67%   -0.01%     
==========================================
  Files        1088     1088              
  Lines      367591   367618      +27     
  Branches   367591   367618      +27     
==========================================
+ Hits       296563   296572       +9     
- Misses      53374    53385      +11     
- Partials    17654    17661       +7     

☔ View full report in Codecov by Harness.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

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

Labels

physical-plan Changes to the physical-plan crate

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants