Dandandan commented on code in PR #24517:
URL: https://github.com/apache/datafusion/pull/24517#discussion_r3821942986


##########
datafusion/physical-plan/src/joins/sort_merge_join/exec.rs:
##########
@@ -832,14 +927,20 @@ impl SortMergeJoinExec {
             })
             .collect();
 
-        Ok(Arc::new(Self::try_new(
-            left,
-            right,
-            on,
-            filter,
-            join_type,
-            sort_options,
-            null_equality,
-        )?))
+        let projection = (!projection.is_empty())
+            .then(|| projection.iter().map(|index| *index as usize).collect());
+
+        Ok(Arc::new(
+            Self::try_new(
+                left,
+                right,
+                on,
+                filter,
+                join_type,
+                sort_options,
+                null_equality,
+            )?
+            .with_projection(projection)?,

Review Comment:
   Good catch, fixed in dc0e106 — `swap_inputs` now renumbers through 
`swap_join_projection`, and skips `reorder_output_after_swap` when a projection 
is present, as hash join does. That also retires the `TODO` that was sitting 
right there.
   
   It was a silent wrong-columns bug rather than a plan-shape one, so there is 
a test that fails without the fix: swapping a join projecting `[4, 2]` emitted 
`[b1, c2]` instead of `[b2, c1]`.



##########
datafusion/physical-plan/src/joins/sort_merge_join/exec.rs:
##########
@@ -832,14 +927,20 @@ impl SortMergeJoinExec {
             })
             .collect();
 
-        Ok(Arc::new(Self::try_new(
-            left,
-            right,
-            on,
-            filter,
-            join_type,
-            sort_options,
-            null_equality,
-        )?))
+        let projection = (!projection.is_empty())
+            .then(|| projection.iter().map(|index| *index as usize).collect());
+
+        Ok(Arc::new(
+            Self::try_new(
+                left,
+                right,
+                on,
+                filter,
+                join_type,
+                sort_options,
+                null_equality,
+            )?
+            .with_projection(projection)?,

Review Comment:
   👍 



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