fix(merge_insert): use sentinel column for NULL-safe source row detection#6439
Merged
wjones127 merged 4 commits intoApr 8, 2026
Merged
Conversation
…tion Source rows with NULL ON key columns were silently dropped because the action assignment logic used `ON_col IS NOT NULL` as a proxy for "source row is present in the join output". This conflates a legitimate NULL key with a NULL introduced by the outer join on the target side. Fix by injecting a `lit(true)` sentinel column into the source DataFrame before the join. After the join the sentinel is non-null for every source row and null only for target-only rows, making source row detection independent of ON column values. Strip the sentinel in `prepare_stream_schema` before writing and propagate it through projection pushdown in `necessary_children_exprs`. Signed-off-by: Pratik <pratikrocks.dey11@gmail.com>
Contributor
Author
|
Hi @wjones127 can you pls provide a review |
wjones127
approved these changes
Apr 8, 2026
Contributor
wjones127
left a comment
There was a problem hiding this comment.
This looks like a nice fix. There's some optional simplifications you can do with the tests. I've commented on one tests, but similar changes can be made to the others.
I will merge tomorrow to give you time to address those if you want.
Contributor
Author
|
Thanks for the super fast review @wjones127 🙌 trying to adress the suggestions shortly |
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
Signed-off-by: Pratik <pratikrocks.dey11@gmail.com>
Signed-off-by: Pratik <pratikrocks.dey11@gmail.com>
…mn index sensitivity The sentinel column added in the Rust fix changed the column indices in the ProjectionExec expressions (e.g. _rowid@1 -> _rowid@0), breaking the doctest pattern matches. Replace the specific column expressions with [...] so the tests don't break when internal indices shift. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
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.
Source rows with NULL ON key columns were silently dropped because the action assignment logic used
ON_col IS NOT NULLas a proxy for "source row is present in the join output". This conflates a legitimate NULL key with a NULL introduced by the outer join on the target side.Fix by injecting a
lit(true)sentinel column into the source DataFrame before the join. After the join the sentinel is non-null for every source row and null only for target-only rows, making source row detection independent of ON column values.Strip the sentinel in
prepare_stream_schemabefore writing and propagate it through projection pushdown innecessary_children_exprs.Before the join, inject a constant
lit(true)column (__merge_source_sentinel) into every source row. After the join:assign_action now uses sentinel IS NOT NULL to detect source row presence, making it correct regardless of what values the ON columns hold.
The sentinel is a pure logical column — it never touches disk. It's stripped in prepare_stream_schema before any data is written, and necessary_children_exprs is updated to propagate it through DataFusion's projection pushdown.
Example that was broken before:
Fixes: #4644