Jefffrey commented on code in PR #9607:
URL: https://github.com/apache/arrow-rs/pull/9607#discussion_r2994076190


##########
arrow-data/src/transform/union.rs:
##########
@@ -68,10 +69,43 @@ pub(super) fn build_extend_dense(array: &ArrayData) -> 
Extend<'_> {
     )
 }
 
-pub(super) fn extend_nulls_dense(_mutable: &mut _MutableArrayData, _len: 
usize) {
-    panic!("cannot call extend_nulls on UnionArray as cannot infer type");
+pub(super) fn extend_nulls_dense(mutable: &mut _MutableArrayData, len: usize) {
+    let DataType::Union(fields, _) = &mutable.data_type else {
+        unreachable!()
+    };
+    let first_type_id = fields
+        .iter()
+        .next()
+        .expect("union must have at least one field")
+        .0;
+
+    // Extend type_ids buffer
+    mutable.buffer1.extend_from_slice(&vec![first_type_id; len]);
+
+    // Dense: extend offsets pointing into the first child, then extend nulls 
in that child
+    let child_offset = mutable.child_data[0].len();
+    mutable
+        .buffer2
+        .extend((0..len).map(|i| (child_offset + i) as i32));

Review Comment:
   ```suggestion
       let (start, end) = (child_offset as i32, (child_offset + len) as i32);
       mutable.buffer2.extend(start..end);
   ```



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