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


##########
arrow-cast/src/cast/list.rs:
##########
@@ -212,6 +212,55 @@ where
     Ok(Arc::new(array))
 }
 
+pub(crate) fn cast_list_view_to_fixed_size_list<O: OffsetSizeTrait>(
+    array: &dyn Array,
+    field: &FieldRef,
+    size: i32,
+    cast_options: &CastOptions,
+) -> Result<ArrayRef, ArrowError> {
+    let array = array.as_list_view::<O>();
+
+    let nullable = cast_options.safe || array.null_count() != 0;
+    let mut nulls = nullable.then(|| {
+        let mut buffer = BooleanBufferBuilder::new(array.len());
+        match array.nulls() {
+            Some(n) => buffer.append_buffer(n.inner()),
+            None => buffer.append_n(array.len(), true),
+        }
+        buffer
+    });
+
+    let values = array.values().to_data();
+    let cap = array.len() * size as usize;
+    let mut mutable = MutableArrayData::new(vec![&values], nullable, cap);
+
+    for idx in 0..array.len() {
+        let offset = array.value_offset(idx).as_usize();
+        let len = array.value_size(idx).as_usize();
+
+        if len != size as usize {
+            // Nulls in FixedSizeListArray take up space and so we must pad 
the values
+            if cast_options.safe || array.is_null(idx) {
+                mutable.extend_nulls(size as _);
+                nulls.as_mut().unwrap().set_bit(idx, false);

Review Comment:
   Essentially yeah; I'll give the `NullBufferBuilder` idea a shot to see if 
can simplify this



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