Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: Skip buffered rows which are not joined with streamed side when checking join filter results #12159

Merged
merged 1 commit into from
Aug 26, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions datafusion/physical-plan/src/joins/sort_merge_join.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1474,6 +1474,12 @@ impl SMJStream {
[chunk.buffered_batch_idx.unwrap()];

for i in 0..pre_mask.len() {
// If the buffered row is not joined with streamed side,
// skip it.
if buffered_indices.is_null(i) {
continue;
}

Comment on lines +1477 to +1482
Copy link
Member Author

@viirya viirya Aug 25, 2024

Choose a reason for hiding this comment

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

I was trying to duplicate the Spark SQL test but the test failure depends on the data distribution. I cannot make it as same as Spark case.

The test case looks like

select * from (
with left as (
    select N, L from (select unnest(make_array(1, 2, 3, 4)) N, unnest(make_array('A', 'B', 'C', 'D')) L) where N <= 4
), right as (
    select N, L from (select unnest(make_array(1, 2, 3, 4)) N, unnest(make_array('A', 'B', 'C', 'D')) L) where N >= 3
)
select * from left full join right on left.N = right.N and left.N != 3
) order by 1, 2, 3, 4;

I want those values to be in same partition to run sort merge join. So the joined batch looks like:

1 A null null
2 B null null # this and above row wrongly considered passing join filter for buffered row [3, C]
3 C 3 C   # join filter => false
4 D 4 D   # join filter => true

The buffered row [3, C] fails join filter. So it should be output as null joined buffered row, but the two above rows are wrongly considered passing join filter for buffered index 0 (i.e., [3, C]), it will not be output in Comet.

Copy link
Member Author

Choose a reason for hiding this comment

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

The test case in Comet is apache/datafusion-comet#553 (comment)

let buffered_index = buffered_indices.value(i);

buffered_batch.join_filter_failed_map.insert(
Expand Down