Skip to content

Commit 8a964a8

Browse files
committed
fix: revalidate prepared joins at execution
1 parent afb0a9a commit 8a964a8

2 files changed

Lines changed: 46 additions & 0 deletions

File tree

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1751,6 +1751,8 @@ impl ExecutionPlan for HashJoinExec {
17511751

17521752
let left_fut = match (&self.prepared_build, self.mode) {
17531753
(Some(prepared), _) => {
1754+
// Public join fields can change after builder validation.
1755+
prepared.validate(self)?;
17541756
let prepared = Arc::clone(prepared);
17551757
self.left_fut.try_once(|| {
17561758
Ok(async move { Ok(prepared.probe_data(right_partitions)) })

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

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,6 +552,50 @@ async fn prepared_build_validates_descriptor_and_builder_changes() -> Result<()>
552552
Ok(())
553553
}
554554

555+
#[tokio::test]
556+
async fn prepared_build_revalidates_public_keys_at_execution() -> Result<()> {
557+
let build = batch(vec![Some(1), Some(2)]);
558+
let base = join(build.schema(), build.clone())?;
559+
let keys: JoinOn = vec![(
560+
Arc::new(Column::new("payload", 1)),
561+
Arc::new(Column::new("payload", 1)),
562+
)];
563+
let ordinary = base
564+
.builder()
565+
.with_on(keys.clone())
566+
.with_new_children(vec![
567+
TestMemoryExec::try_new_exec(&[vec![build.clone()]], build.schema(), None)?,
568+
Arc::clone(base.right()),
569+
])?
570+
.build()?;
571+
assert_batches_eq!(
572+
[
573+
"+-----+---------+-----+---------+",
574+
"| key | payload | key | payload |",
575+
"+-----+---------+-----+---------+",
576+
"| 1 | 10 | 1 | 10 |",
577+
"| 2 | 11 | 2 | 11 |",
578+
"+-----+---------+-----+---------+",
579+
],
580+
&run(&ordinary).await?
581+
);
582+
583+
let prepared =
584+
prepare(&base, vec![build], Arc::new(GreedyMemoryPool::new(1 << 20))).await?;
585+
let mut attached = base.builder().with_prepared_build(prepared).build()?;
586+
attached.on = keys;
587+
let error = run(&attached)
588+
.await
589+
.expect_err("changed public keys must not probe the old prepared table");
590+
assert!(matches!(error, DataFusionError::Plan(_)), "{error}");
591+
assert!(
592+
error
593+
.to_string()
594+
.contains("does not match schema, keys or null equality")
595+
);
596+
Ok(())
597+
}
598+
555599
#[tokio::test]
556600
async fn prepared_build_rejects_view_payload_before_consumption() -> Result<()> {
557601
let build = RecordBatch::try_from_iter([

0 commit comments

Comments
 (0)