alamb commented on code in PR #12212:
URL: https://github.com/apache/arrow-rs/pull/12212#discussion_r4568078515


##########
arrow-select/src/coalesce/byte_view.rs:
##########
@@ -462,6 +466,77 @@ impl<B: ByteViewType> InProgressByteViewArray<B> {
                 .next_buffer(selected_bytes.min(max_buffer_size)),
         };
 
+        if selected_bytes > max_buffer_size {
+            // SAFETY: the caller guarantees the index, view, byte-count, and
+            // per-value size invariants required by the delegated operation.
+            unsafe {
+                self.append_indexed_views_and_copy_strings_split(
+                    src_views,
+                    indices,
+                    src_buffers,
+                    selected_bytes,
+                    max_buffer_size,
+                    dst_buffer,
+                )
+            };
+            return;
+        }
+
+        let current_len = self.views.len();
+        self.views.reserve(indices.len());
+        let output = 
self.views.spare_capacity_mut().as_mut_ptr().cast::<u128>();
+
+        let buffer_index = self.completed.len().try_into().expect("too many 
buffers");
+        for (i, &idx) in indices.iter().enumerate() {
+            // SAFETY: caller validated idx < src_views.len().
+            let raw = unsafe { *src_views.get_unchecked(idx as usize) };
+            let mut view = ByteView::from(raw);
+            if view.length > MAX_INLINE_VIEW_LEN {
+                let source_buffer_index = view.buffer_index as usize;
+                let source_buffer_offset = view.offset as usize;
+                let length = view.length as usize;
+
+                // SAFETY: source views carry valid buffer_index/offset/length.
+                let src = unsafe {
+                    src_buffers
+                        .get_unchecked(source_buffer_index)
+                        
.get_unchecked(source_buffer_offset..source_buffer_offset + length)
+                };
+                view.offset = dst_buffer
+                    .len()
+                    .try_into()
+                    .expect("byte view offset exceeds u32::MAX");

Review Comment:
   You could check this once outside the loop potentially (that 
dst_buffer.len() + selected_bytes < u32::MAX) and then skip the check here



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

Reply via email to