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


##########
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:
   how do we know here `nulls` is non null? Maybe because above `arrays.nulls` 
would have set it?



##########
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(|| {

Review Comment:
   You may be able to use NullBufferBuilder here simplify the null handling (it 
already has a `Option<...>` internally to avoid allocating if there are no nulls
   
   I think you would have to add `set_bit` in NullBufferBuilder but that is 
probably useful anyways



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