Repository navigation
fix: evaluate sort-merge join filters that reference no columns - #26010
Open
mrhard9090 wants to merge 1 commit into
Open
mrhard9090 wants to merge 1 commit into
mrhard9090 wants to merge 1 commit into
Conversation
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
Codecov Report❌ Patch coverage is
Additional details and impacted files@@ Coverage Diff @@
## main #26010 +/- ##
==========================================
- Coverage 82.64% 82.64% -0.01%
==========================================
Files 1147 1147
Lines 445502 445503 +1
Branches 445502 445503 +1
==========================================
- Hits 368179 368169 -10
- Misses 54969 54975 +6
- Partials 22354 22359 +5 ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
Contributor
|
@mrhard9090 , overall LGTM, please fix the conflicts Same bug in the semi/anti/mark stream: with a column-free filter, - let filter_batch = RecordBatch::try_new(Arc::clone(filter.schema()), columns)?;
+ let filter_batch = RecordBatch::try_new_with_options(
+ Arc::clone(filter.schema()),
+ columns,
+ &RecordBatchOptions::new().with_row_count(Some(num_outer_rows)),
+ )?;Test (fails on this branch, passes with the fix): #[tokio::test]
async fn join_semi_anti_mark_column_free_filter() -> Result<()> {
for join_type in [
LeftSemi, LeftAnti, LeftMark, RightSemi, RightAnti, RightMark,
] {
let left = build_table(
("a1", &vec![1, 2, 3]),
("b1", &vec![4, 5, 7]),
("c1", &vec![7, 8, 9]),
);
let right = build_table(
("a2", &vec![10, 20, 30]),
("b1", &vec![4, 5, 6]),
("c2", &vec![70, 80, 90]),
);
let on = vec![(
Arc::new(Column::new_with_schema("b1", &left.schema())?) as _,
Arc::new(Column::new_with_schema("b1", &right.schema())?) as _,
)];
let filter = JoinFilter::new(
Arc::new(Literal::new(ScalarValue::Boolean(Some(false)))),
vec![],
Arc::new(Schema::empty()),
);
let (_, batches) =
join_collect_with_filter(left, right, on, filter, join_type).await?;
let rows: usize = batches.iter().map(|b| b.num_rows()).sum();
let expected = match join_type {
LeftSemi | RightSemi => 0,
_ => 3,
};
assert_eq!(rows, expected, "{join_type:?}");
}
Ok(())
} |
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
SortMergeJoinExeconly evaluated its join filter when the filter read at least one column. A filter that reads none (a bound parameter such as$1 > 5, or a volatile function such asrandom() > 2) was skipped, so every key match was kept. ForFULL JOINthat returns matched pairs the filter rejects, where hash join null-pads both sides.What changes are included in this PR?
freeze_streamed_matched(sort_merge_join/materializing_stream.rs) now evaluates the filter whenever the join has one. The filter batch is built withRecordBatchOptions::with_row_count(total_matched_rows), because a batch with no columns cannot infer its row count.sort_merge_join.slt:FULL JOIN ... AND random() > 2(every row null-padded) andAND random() < 2(all key matches kept).I did not touch
bitwise_stream.rs(semi/anti/mark joins), which builds its filter batch in a different place.What is the testing strategy for this PR?
cargo test -p datafusion-sqllogictest --test sqllogictests -- sort_merge_join: all 4 files pass. With thematerializing_stream.rschange reverted,sort_merge_join.sltfails.cargo test -p datafusion-physical-plan --lib sort_merge_join: 247 passed.cargo fmtandcargo clippy -p datafusion-physical-plan --all-targets -- -D warningspass.Are there any user-facing changes?
FULL JOIN(and other join types run by sort-merge join) with a column-freeONcondition now returns the same rows as hash join. No API change.AI assistance: written with Claude Code; I reproduced the bug, reviewed the diff and ran the tests above.