Skip to content

Commit a00f749

Browse files
authored
fix: add assert to HashJoinExec::swap_inputs (#23078)
## Which issue does this PR close? <!-- We generally require a GitHub issue to be filed for all bug fixes and enhancements and this helps us generate change logs for our releases. You can link an issue to this PR using the GitHub syntax. For example `Closes #123` indicates that this PR will close issue #123. --> - Closes #23077 ## Rationale for this change Dynamic filters are runtime state tied to the probe side. `swap_inputs` changes the probe side, so preserving the old filter is unsafe and can lead to wrong column references. ## What changes are included in this PR? remove the `dynamic_filter` while swap inputs in `HashJoinExec`: ```rust .with_dynamic_filter(None) ``` ## Are these changes tested? yes, add one test case ## Are there any user-facing changes? no
1 parent afdc003 commit a00f749

1 file changed

Lines changed: 45 additions & 0 deletions

File tree

  • datafusion/physical-plan/src/joins/hash_join

‎datafusion/physical-plan/src/joins/hash_join/exec.rs‎

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1092,6 +1092,12 @@ impl HashJoinExec {
10921092
&self,
10931093
partition_mode: PartitionMode,
10941094
) -> Result<Arc<dyn ExecutionPlan>> {
1095+
assert_or_internal_err!(
1096+
self.dynamic_filter.is_none(),
1097+
"Cannot swap HashJoinExec inputs after dynamic filters have been constructed. \
1098+
Optimizer rules that reorder join inputs must run before optimizer rules `FilterPushdown::new_post_optimization()`"
1099+
);
1100+
10951101
let left = self.left();
10961102
let right = self.right();
10971103
let new_join = self
@@ -6627,6 +6633,45 @@ mod tests {
66276633
Ok(())
66286634
}
66296635

6636+
#[test]
6637+
fn test_swap_inputs_rejects_dynamic_filter() -> Result<()> {
6638+
let left = build_table(
6639+
("l_key", &vec![1]),
6640+
("l_payload", &vec![10]),
6641+
("l_other", &vec![100]),
6642+
);
6643+
let right = build_table(
6644+
("r_payload", &vec![20]),
6645+
("r_key", &vec![1]),
6646+
("r_other", &vec![200]),
6647+
);
6648+
let on = vec![(
6649+
Arc::new(Column::new_with_schema("l_key", &left.schema())?) as _,
6650+
Arc::new(Column::new_with_schema("r_key", &right.schema())?) as _,
6651+
)];
6652+
6653+
let dynamic_filter = HashJoinExec::create_dynamic_filter(&on);
6654+
let join = HashJoinExec::try_new(
6655+
left,
6656+
right,
6657+
on,
6658+
None,
6659+
&JoinType::LeftSemi,
6660+
None,
6661+
PartitionMode::CollectLeft,
6662+
NullEquality::NullEqualsNothing,
6663+
false,
6664+
)?
6665+
.with_dynamic_filter_expr(dynamic_filter)?;
6666+
6667+
let err = join.swap_inputs(PartitionMode::CollectLeft).unwrap_err();
6668+
assert_contains!(
6669+
err.to_string(),
6670+
"Cannot swap HashJoinExec inputs after dynamic filters have been constructed"
6671+
);
6672+
Ok(())
6673+
}
6674+
66306675
#[test]
66316676
fn test_dynamic_filter_pushdown_rejects_null_equal_join() -> Result<()> {
66326677
let (_, _, on) = build_schema_and_on()?;

0 commit comments

Comments
 (0)