samuelcolvin commented on code in PR #6218:
URL: https://github.com/apache/arrow-rs/pull/6218#discussion_r1711787950


##########
arrow-cast/src/cast/mod.rs:
##########
@@ -2417,9 +2518,37 @@ where
     Ok(Arc::new(byte_array_builder.finish()))
 }
 
+/// Get a field of the union as an array, this is equivalent to 
[`UnionArray::child`] for sparse unions,
+/// but builds an array of the right length for dense unions.
+///
+/// # Panics
+/// Panics if `type_id` is not present in the union.
+fn union_field_array(union_array: &UnionArray, type_id: i8) -> 
Result<Cow<ArrayRef>, ArrowError> {
+    let child = union_array.child(type_id);
+    match union_array.offsets() {
+        Some(offsets) => {
+            let data_type = child.data_type();
+            let sub_arrays: Vec<ArrayRef> = offsets
+                .iter()
+                .zip(union_array.type_ids().iter())
+                .map(|(offset, id)| {
+                    if id == &type_id {
+                        child.slice(*offset as usize, 1)
+                    } else {
+                        new_null_array(data_type, 1)

Review Comment:
   I wonder how slow this will be?
   
   In theory we could do something cleverer where we build up chunks rather 
than having a separate array for each element, but I've no idea how much 
difference it will make.
   
   More to the point I wonder if there's a completely different way to do this 
that's much faster?



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