Repository navigation
Conversation
…der (apache#24573) Partial backport of d1fe988 (apache#24573) to branch-54: only the ordering fix and its regression tests. LEFT/RIGHT/FULL sort-merge joins with a join filter advertise that they preserve the order of one input (`maintains_input_order`), but the final flush at end-of-input returned its filtered batch directly. Rows still buffered in `self.output` from an earlier flush were then emitted *after* it. The final batch is now staged in `self.output` and drained through the same buffer, so all deferred-filtered output leaves in order. Not backported: the other changes in apache#24573 (`join_arrays` returning `Result`, the direct-addressed source lookup in `materialize_right_columns`, `new_output_coalescer`). They are refactors/perf work that do not apply to the pre-generator code on this branch and are not needed for the fix. Tests: `left_join_with_filter_preserves_streamed_order`, `right_join_with_filter_preserves_streamed_order` and `left_join_with_partial_filter_preserves_streamed_order`, with their helpers, taken from apache#24573. All three fail on branch-54 without the fix. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
3 of 18 tasks
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?
54.2.0(minor/patch) Release #23805 (the 54.2.0 patch release tracking issue).branch-54.Rationale for this change
LEFT,RIGHTandFULLsort-merge joins with a join filter can return rows out of order. These join types advertise that they preserve the order of one input (maintains_input_orderis[true, false]forLEFT), so an operator above is allowed to rely on it. Deferred-filtered joins stage their output in a secondBatchCoalescer(self.output), but in theExhaustedstatepoll_nextreturned the final filtered batch directly, so rows still buffered inoutputfrom an earlier flush came out after it.The three streamed-order tests from #24573 fail on
branch-54as they do onmain: for theLEFT JOINshape with mixed group sizes the streamed keys come back as[5, 6, 0, 1, 2, 3, 4]instead of[0, 1, 2, 3, 4, 5, 6]. This is a wrong result, which makes it eligible for backport.#24573 fixed it on
main(labelledv56.0.0); it is onbranch-56but not onbranch-54. It was requested forbranch-54on #26868 (#26868 (comment)), "to prevent regressions on upgrade to 54".What changes are included in this PR?
This is a partial port, not a plain cherry-pick. The sort-merge join on this branch predates the generator refactor (#23761, #23976), and a cherry-pick of #24573 conflicts in nine places in
materializing_stream.rs(and once intests.rs) because most of that commit refactors code that is different here. Only the ordering fix and its tests are ported:datafusion/physical-plan/src/joins/sort_merge_join/materializing_stream.rs: in theExhaustedstate the final filtered batch is pushed intoself.outputinstead of being returned directly. The existing drain ofself.outputbelow it then emits it, in order, after the rows that were already staged there.datafusion/physical-plan/src/joins/sort_merge_join/tests.rs:left_join_with_filter_preserves_streamed_order,right_join_with_filter_preserves_streamed_orderandleft_join_with_partial_filter_preserves_streamed_order, with their helpers, taken from fix: ensure deferred-filtered outer joins preserve streamed output order #24573.Not ported, because they are refactors or performance work on code that is different here and the fix does not need them:
join_arraysreturningResult, the direct-addressed source lookup inmaterialize_right_columnsand its two tests,new_output_coalescer, and the benchmark change.Are these changes tested?
Yes. On this branch (Rust 1.95.0) I ran:
cargo test -p datafusion-physical-plan --lib sort_merge_joinfails exactly those three.cargo test -p datafusion-physical-plan --lib: 1442 passed, including the three.cargo test -p datafusion-sqllogictest --test sqllogictests -- join: all 14 matching files pass.cargo fmt --all -- --checkandcargo clippy -p datafusion-physical-plan --all-targets --all-features -- -D warningspass.Are there any user-facing changes?
Outer sort-merge joins with a join filter return rows in the order they advertise. No public API change.
🤖 Generated with Claude Code