UBarney commented on code in PR #16443: URL: https://github.com/apache/datafusion/pull/16443#discussion_r2181428292
########## datafusion/physical-plan/src/joins/nested_loop_join.rs: ########## @@ -883,44 +1000,63 @@ impl<T: BatchTransformer> NestedLoopJoinStream<T> { let visited_left_side = left_data.bitmap(); let batch = self.state.try_as_process_probe_batch()?; - match self.batch_transformer.next() { - None => { - // Setting up timer & updating input metrics - self.join_metrics.input_batches.add(1); - self.join_metrics.input_rows.add(batch.num_rows()); - let timer = self.join_metrics.join_time.timer(); - - let result = join_left_and_right_batch( - left_data.batch(), - batch, - self.join_type, - self.filter.as_ref(), - &self.column_indices, - &self.schema, - visited_left_side, - &mut self.indices_cache, - self.right_side_ordered, - ); - timer.done(); + let binding = self.join_metrics.join_time.clone(); + let _timer = binding.timer(); + + if self.join_result_status.is_none() { + let (left_side_indices, right_side_indices) = join_left_and_right_batch( + left_data.batch(), + batch, + self.join_type, + self.filter.as_ref(), + visited_left_side, + &mut self.indices_cache, + self.right_side_ordered, + self.intermediate_batch_size, + )?; + self.join_result_status = Some((left_side_indices, right_side_indices, 0)) + } + + let join_result = self.get_next_join_result()?; - self.batch_transformer.set_batch(result?); + match join_result { + Some(res) => { + self.join_metrics.output_batches.add(1); + self.join_metrics.output_rows.add(res.num_rows()); + + Ok(StatefulStreamResult::Ready(Some(res))) + } + None => { + self.state = NestedLoopJoinStreamState::FetchProbeBatch; + self.join_result_status = None; Ok(StatefulStreamResult::Continue) } - Some((batch, last)) => { - if last { - self.state = NestedLoopJoinStreamState::FetchProbeBatch; - } + } + } - self.join_metrics.output_batches.add(1); - self.join_metrics.output_rows.add(batch.num_rows()); - Ok(StatefulStreamResult::Ready(Some(batch))) + fn build_unmatched_output( + &mut self, + ) -> Result<StatefulStreamResult<Option<RecordBatch>>> { + if matches!( Review Comment: Yes, we don't need this check -- 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