andygrove commented on code in PR #27278:
URL: https://github.com/apache/datafusion/pull/27278#discussion_r4747423543
##########
datafusion/physical-plan/src/joins/sort_merge_join/tests.rs:
##########
@@ -8395,3 +8401,299 @@ async fn
left_join_with_partial_filter_preserves_streamed_order() -> Result<()>
);
Ok(())
}
+
+// ============================================================================
+// Early filtering of Inner joins
+// ============================================================================
+
+/// Rows for the early-filtering tests, sorted by the key column `names[0]`:
key
+/// `k` of `0..keys` has `rows_per_key(k)` rows. `names[1]` is the row number
and
+/// `names[2]` a pseudo-random value in `0..1000` that is NULL in every 37th
row.
+/// The rows are split into batches of `rows_per_batch`.
+fn early_filtering_batches(
+ names: [&str; 3],
+ keys: i32,
+ rows_per_key: impl Fn(i32) -> usize,
+ seed: u64,
+ rows_per_batch: usize,
+) -> (Vec<RecordBatch>, SchemaRef) {
+ let mut key_values = vec![];
+ let mut row_numbers = vec![];
+ let mut values = vec![];
+ let mut state = seed;
+ for key in 0..keys {
+ for _ in 0..rows_per_key(key) {
+ state = state
+ .wrapping_mul(6364136223846793005)
+ .wrapping_add(1442695040888963407);
+ let row = key_values.len() as i32;
+ key_values.push(key);
+ row_numbers.push(row);
+ values.push((row % 37 != 0).then_some(((state >> 33) % 1000) as
i32));
+ }
+ }
+ let schema = Arc::new(Schema::new(vec![
+ Field::new(names[0], DataType::Int32, false),
+ Field::new(names[1], DataType::Int32, false),
+ Field::new(names[2], DataType::Int32, true),
+ ]));
+ let batch = RecordBatch::try_new(
+ Arc::clone(&schema),
+ vec![
+ Arc::new(Int32Array::from(key_values)),
+ Arc::new(Int32Array::from(row_numbers)),
+ Arc::new(Int32Array::from(values)),
+ ],
+ )
+ .unwrap();
+ let batches = (0..batch.num_rows())
+ .step_by(rows_per_batch)
+ .map(|offset| batch.slice(offset, rows_per_batch.min(batch.num_rows()
- offset)))
+ .collect();
+ (batches, schema)
+}
+
+/// Inputs for the early-filtering tests. Every third key has a group of 600
+/// buffered rows, which the 250-row buffered batches split, so that a freeze
+/// gathers its pairs from several buffered batches. The other keys have
groups of
+/// one or two buffered rows. Keys repeat up to four times on the streamed
side.
+fn early_filtering_inputs()
+-> ((Vec<RecordBatch>, SchemaRef), (Vec<RecordBatch>, SchemaRef)) {
+ let left =
+ early_filtering_batches(["a1", "b1", "c1"], 40, |k| 1 + (k % 4) as
usize, 1, 7);
Review Comment:
Every key here is on both sides, so
`join_with_projection_matches_projected_join` never emits a row without a
match. Those rows take the paths whose column lists this PR changed:
`materialize_columns` and `create_unmatched_columns` in `freeze_streamed`, and
`produce_buffered_null_batch` in `freeze_buffered`. I changed each of those
three call sites to pass the `*_gathered_columns` list instead, which makes a
join fail when its projection drops a column the filter reads, and all 499 SMJ
tests still passed.
With the change below, each of the three makes the projection test fail, and
the other tests still pass. The left side gets keys past the right side's last
key, because a streamed row without a match only takes the `freeze_streamed`
path once no buffered rows are left. The right side gets keys of its own for
the Full join.
```suggestion
/// one or two buffered rows. Keys repeat up to four times on the streamed
side.
/// Only the left side has keys 40 to 43, which follow the right side's last
key,
/// and only the right side has every seventh key from 3, so that outer
joins also
/// emit rows without a match.
fn early_filtering_inputs()
-> ((Vec<RecordBatch>, SchemaRef), (Vec<RecordBatch>, SchemaRef)) {
let left = early_filtering_batches(
["a1", "b1", "c1"],
44,
|k| if k % 7 == 3 { 0 } else { 1 + (k % 4) as usize },
1,
7,
);
```
--
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]