comphead commented on code in PR #16210: URL: https://github.com/apache/datafusion/pull/16210#discussion_r2125246086
########## datafusion/physical-plan/src/joins/nested_loop_join.rs: ########## @@ -1129,6 +1316,95 @@ pub(crate) mod tests { ) } + fn build_left_table_equijoin() -> Arc<dyn ExecutionPlan> { + build_table( + ("a1", &vec![12, 2, 11]), + ("b1", &vec![2, 2, 8]), + ("c1", &vec![50, 90, 110]), + None, + Vec::new(), + ) + } + + fn build_right_table_equijoin() -> Arc<dyn ExecutionPlan> { + build_table( + ("a2", &vec![12, 2, 10]), + ("b2", &vec![10, 2, 10]), + ("c2", &vec![40, 80, 100]), + None, + Vec::new(), + ) + } + + /// This builds table with nullable values (uses same logic as `build_table` above) + fn build_table_null( + a: (&str, &Vec<Option<i32>>), + b: (&str, &Vec<Option<i32>>), + c: (&str, &Vec<Option<i32>>), + batch_size: Option<usize>, + sorted_column_names: Vec<&str>, + ) -> Arc<dyn ExecutionPlan> { + // build 0 or more sliced RecordBatches with nullable values + let batch = build_table_i32_null(a, b, c); + let schema = batch.schema(); + + let batches = if let Some(batch_size) = batch_size { + let num_batches = batch.num_rows().div_ceil(batch_size); + (0..num_batches) + .map(|i| { + let start = i * batch_size; + let remaining_rows = batch.num_rows() - start; + batch.slice(start, batch_size.min(remaining_rows)) + }) + .collect::<Vec<_>>() + } else { + vec![batch] + }; + + // create the in‑memory source + let mut source = + TestMemoryExec::try_new(&[batches], Arc::clone(&schema), None).unwrap(); + + // attach sort information if requested + if !sorted_column_names.is_empty() { + let mut sort_info = LexOrdering::default(); + for name in sorted_column_names { + let idx = schema.index_of(name).unwrap(); + sort_info.push(PhysicalSortExpr { + expr: Arc::new(Column::new(name, idx)), + options: SortOptions { + descending: false, + nulls_first: false, + }, + }); + } + source = source.try_with_sort_information(vec![sort_info]).unwrap(); + } + + // wrap in cache and return + Arc::new(TestMemoryExec::update_cache(Arc::new(source))) + } + + fn build_left_table_null() -> Arc<dyn ExecutionPlan> { Review Comment: a nit: but I think it would be easier to show the table contents in the content. The table can be built in text format like here https://www.tablesgenerator.com/text_tables -- 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: github-unsubscr...@datafusion.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: github-unsubscr...@datafusion.apache.org For additional commands, e-mail: github-h...@datafusion.apache.org