refactor: Simplify NLJ re-scans with ReplayableStreamSource#21742
Open
2010YOUY01 wants to merge 10 commits intoapache:mainfrom
Open
refactor: Simplify NLJ re-scans with ReplayableStreamSource#217422010YOUY01 wants to merge 10 commits intoapache:mainfrom
ReplayableStreamSource#217422010YOUY01 wants to merge 10 commits intoapache:mainfrom
Conversation
2010YOUY01
commented
Apr 20, 2026
martin-g
reviewed
Apr 20, 2026
Co-authored-by: Martin Grigorov <martin-g@users.noreply.github.com>
martin-g
approved these changes
Apr 21, 2026
Member
martin-g
left a comment
There was a problem hiding this comment.
Thanks!
Few nitpicks which you could just ignore!
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Which issue does this PR close?
Rationale for this change
Background
#21448 introduced memory-limited execution for NLJ (thanks to @viirya).
The idea is:
To support repeated probing of the right side, input batches are spilled to disk during the first pass. In subsequent passes, input is read directly from the spill. This avoids re-evaluating potentially expensive pipelines (e.g., Parquet decoding + filtering), making repeated probes both memory-efficient and fast.
This PR
This PR extracts the spill-backed replayable stream into a separate module to simplify the NLJ implementation.
Although the lines of code increase, the new module provides a clearer interface and I think it's easier to maintain.
Additionally, this utility may be useful elsewhere. I have seen a similar pattern in SedonaDB for memory-limited spatial joins.
What changes are included in this PR?
ReplayableStreamSourcefor the above purposeReplayableStreamSourceAre these changes tested?
UTs, also covered by existing memory-limited NLJ test
Are there any user-facing changes?
No