mbutrovich commented on code in PR #27750:
URL: https://github.com/apache/datafusion/pull/27750#discussion_r4699255954
##########
datafusion/physical-plan/src/joins/hash_join/exec.rs:
##########
@@ -8444,6 +8444,57 @@ mod tests {
.await;
}
+ #[tokio::test]
+ async fn join_stops_consuming_probe_at_fetch_with_empty_build_map() ->
Result<()> {
+ let schema =
+ Arc::new(Schema::new(vec![Field::new("key", DataType::Int32,
true)]));
+ let probe_batch = RecordBatch::try_new(
+ Arc::clone(&schema),
+ vec![Arc::new(Int32Array::from(vec![1, 2, 3]))],
+ )?;
+ let key = Arc::new(Column::new_with_schema("key", &schema)?);
+ let on: JoinOn = vec![(Arc::clone(&key) as _, key)];
+ let fetch = 2;
+
+ for build_keys in [vec![], vec![None]] {
+ let build_batch = RecordBatch::try_new(
+ Arc::clone(&schema),
+ vec![Arc::new(Int32Array::from(build_keys))],
+ )?;
+ let left = TestMemoryExec::try_new_exec(
+ &[vec![build_batch]],
+ Arc::clone(&schema),
+ None,
+ )?;
+ let right = Arc::new(
+ MockExec::new(
+ vec![Ok(probe_batch.clone()), exec_err!("unexpected probe
poll")],
+ Arc::clone(&schema),
+ )
+ .with_use_task(false)
+ .with_unknown_statistics(),
+ );
+ let join = join(
+ left,
+ right,
+ on.clone(),
+ &JoinType::RightAnti,
+ NullEquality::NullEqualsNothing,
+ )?
+ .builder()
+ .with_fetch(Some(fetch))
+ .build()?;
+
+ let stream = join.execute(0, Arc::new(TaskContext::default()))?;
+ assert_eq!(
+ common::collect(stream).await?,
+ vec![probe_batch.slice(0, fetch)]
+ );
+ }
+
+ Ok(())
+ }
Review Comment:
`RightMark` goes through the same empty-map branch as `RightAnti` and has
the same bug. Could we cover it too? The neighboring fetch test
`join_fetch_stops_final_build_rows_mid_chunk` parameterizes over join types
with `#[rstest]`, and the same shape works here. Without the `stream.rs`
change, all four cases below fail with `unexpected probe poll`. With it, they
pass. Checking only the probe column keeps one assertion for both output
schemas.
```suggestion
#[rstest]
#[tokio::test]
async fn join_stops_consuming_probe_at_fetch_with_empty_build_map(
#[values(JoinType::RightAnti, JoinType::RightMark)] join_type:
JoinType,
#[values(vec![], vec![None])] build_keys: Vec<Option<i32>>,
) -> Result<()> {
let schema =
Arc::new(Schema::new(vec![Field::new("key", DataType::Int32,
true)]));
let probe_batch = RecordBatch::try_new(
Arc::clone(&schema),
vec![Arc::new(Int32Array::from(vec![1, 2, 3]))],
)?;
let key = Arc::new(Column::new_with_schema("key", &schema)?);
let on: JoinOn = vec![(Arc::clone(&key) as _, key)];
let fetch = 2;
let build_batch = RecordBatch::try_new(
Arc::clone(&schema),
vec![Arc::new(Int32Array::from(build_keys))],
)?;
let left = TestMemoryExec::try_new_exec(
&[vec![build_batch]],
Arc::clone(&schema),
None,
)?;
let right = Arc::new(
MockExec::new(
vec![Ok(probe_batch.clone()), exec_err!("unexpected probe
poll")],
Arc::clone(&schema),
)
.with_use_task(false)
.with_unknown_statistics(),
);
let join = join(left, right, on, &join_type,
NullEquality::NullEqualsNothing)?
.builder()
.with_fetch(Some(fetch))
.build()?;
let stream = join.execute(0, Arc::new(TaskContext::default()))?;
let batches = common::collect(stream).await?;
let batch = concat_batches(&join.schema(), &batches)?;
assert_eq!(batch.column(0), probe_batch.slice(0, fetch).column(0));
Ok(())
}
```
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]