This is an automated email from the ASF dual-hosted git repository.

westonpace pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/main by this push:
     new 40af786cb1 fix take on empty struct array (#7224)
40af786cb1 is described below

commit 40af786cb12a4b8b20961deb9a14783ce33b4143
Author: Weston Pace <[email protected]>
AuthorDate: Thu Mar 6 14:07:18 2025 -0800

    fix take on empty struct array (#7224)
---
 arrow-select/src/take.rs | 16 +++++++++++++++-
 1 file changed, 15 insertions(+), 1 deletion(-)

diff --git a/arrow-select/src/take.rs b/arrow-select/src/take.rs
index 71a7c77a8f..04a7a606b0 100644
--- a/arrow-select/src/take.rs
+++ b/arrow-select/src/take.rs
@@ -254,7 +254,12 @@ fn take_impl<IndexType: ArrowPrimitiveType>(
                 })
                 .collect();
 
-            Ok(Arc::new(StructArray::from((fields, is_valid))) as ArrayRef)
+            if fields.is_empty() {
+                let nulls = NullBuffer::new(BooleanBuffer::new(is_valid, 0, 
indices.len()));
+                Ok(Arc::new(StructArray::new_empty_fields(indices.len(), 
Some(nulls))))
+            } else {
+                Ok(Arc::new(StructArray::from((fields, is_valid))) as ArrayRef)
+            }
         }
         DataType::Dictionary(_, _) => downcast_dictionary_array! {
             values => Ok(Arc::new(take_dict(values, indices)?)),
@@ -1968,6 +1973,15 @@ mod tests {
         ]);
 
         assert_eq!(&expected, actual);
+
+        let nulls = NullBuffer::from(&[false, true, false, true, false, true]);
+        let empty_struct_arr = StructArray::new_empty_fields(6, Some(nulls));
+        let index = UInt32Array::from(vec![0, 2, 1, 4]);
+        let actual = take(&empty_struct_arr, &index, None).unwrap();
+
+        let expected_nulls = NullBuffer::from(&[false, false, true, false]);
+        let expected_struct_arr = StructArray::new_empty_fields(4, 
Some(expected_nulls));
+        assert_eq!(&expected_struct_arr, actual.as_struct());
     }
 
     #[test]

Reply via email to