alihan-synnada commented on code in PR #12969:
URL: https://github.com/apache/datafusion/pull/12969#discussion_r1804306358


##########
datafusion/physical-plan/src/joins/utils.rs:
##########
@@ -1356,17 +1357,34 @@ pub(crate) fn append_right_indices(
         if right_unmatched_indices.is_empty() {
             (left_indices, right_indices)
         } else {
+            let left_size = left_indices.len();
+            let right_size = right_indices.len();
             let unmatched_size = right_unmatched_indices.len();
+
+            let left_indices_data = left_indices.into_data();
+            let right_indices_data = right_indices.into_data();
+            let right_unmatched_indices_data = 
right_unmatched_indices.into_data();
+
             // the new left indices: left_indices + null array
+            let mut new_left_indices = MutableArrayData::new(
+                vec![&left_indices_data],
+                true,
+                left_size + unmatched_size,
+            );
+            new_left_indices.extend(0, 0, left_size);
+            new_left_indices.extend_nulls(unmatched_size);
+            let new_left_indices = 
UInt64Array::from(new_left_indices.freeze());
+
             // the new right indices: right_indices + right_unmatched_indices
-            let new_left_indices = left_indices
-                .iter()
-                .chain(std::iter::repeat(None).take(unmatched_size))
-                .collect();
-            let new_right_indices = right_indices
-                .iter()
-                .chain(right_unmatched_indices.iter())
-                .collect();
+            let mut new_right_indices = MutableArrayData::new(

Review Comment:
   I tried the following code but it's about 200% slower. Is there a more 
optimized way to use `Vec` in this context?
   
   ```
   // the new left indices: left_indices + null array
   let mut new_left_indices = Vec::with_capacity(left_size + unmatched_size);
   new_left_indices.extend(left_indices.values().iter().map(|v| Some(*v)));
   new_left_indices.append(&mut vec![None; unmatched_size]);
   let new_left_indices = UInt64Array::from(new_left_indices);
   
   // the new right indices: right_indices + right_unmatched_indices
   let mut new_right_indices = Vec::with_capacity(right_size + unmatched_size);
   new_right_indices.extend(right_indices.values().iter());
   new_right_indices.extend(right_unmatched_indices.values().iter());
   let new_right_indices = UInt32Array::from(new_right_indices);
   ```



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