comphead commented on code in PR #11218:
URL: https://github.com/apache/datafusion/pull/11218#discussion_r1678595256


##########
datafusion/physical-plan/src/joins/sort_merge_join.rs:
##########
@@ -1503,12 +1579,39 @@ fn get_buffered_columns(
     buffered_batch_idx: usize,
     buffered_indices: &UInt64Array,
 ) -> Result<Vec<ArrayRef>, ArrowError> {
-    buffered_data.batches[buffered_batch_idx]
-        .batch
-        .columns()
-        .iter()
-        .map(|column| take(column, &buffered_indices, None))
-        .collect::<Result<Vec<_>, ArrowError>>()
+    get_buffered_columns_from_batch(
+        &buffered_data.batches[buffered_batch_idx],
+        buffered_indices,
+    )
+}
+
+#[inline(always)]
+fn get_buffered_columns_from_batch(
+    buffered_batch: &BufferedBatch,
+    buffered_indices: &UInt64Array,
+) -> Result<Vec<ArrayRef>, ArrowError> {
+    if let Some(spill_file) = &buffered_batch.spill_file {
+        // if spilled read from disk in smaller sub batches
+        let mut buffered_cols: Vec<ArrayRef> = 
Vec::with_capacity(buffered_indices.len());
+
+        let file = BufReader::new(File::open(spill_file.path())?);
+        let reader = FileReader::try_new(file, None)?;
+
+        for batch in reader {
+            batch?.columns().iter().for_each(|column| {
+                buffered_cols.extend(take(column, &buffered_indices, None))

Review Comment:
   On this I feel I need to think more. you are right if we save data on 
smaller batches the indices we looking up can return wrong results across 
multiple  batches



-- 
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]

Reply via email to