tustvold commented on code in PR #5081:
URL: https://github.com/apache/arrow-rs/pull/5081#discussion_r1397631553
##########
arrow-cast/src/cast.rs:
##########
@@ -3206,6 +3221,73 @@ where
Ok(Arc::new(list))
}
+fn cast_list_to_fixed_size_list<OffsetSize>(
+ array: &GenericListArray<OffsetSize>,
+ field: &Arc<Field>,
+ size: i32,
+ cast_options: &CastOptions,
+) -> Result<ArrayRef, ArrowError>
+where
+ OffsetSize: OffsetSizeTrait,
+{
+ let cap = array.len() * size as usize;
+
+ let mut nulls = (cast_options.safe || array.null_count() != 0).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
+ });
+
+ // Nulls in FixedSizeListArray take up space and so we must pad the values
+ let values = array.values().to_data();
+ let mut mutable = MutableArrayData::new(vec![&values], cast_options.safe,
cap);
+ let mut last_pos = 0;
+ for (idx, w) in array.offsets().windows(2).enumerate() {
+ let start_pos = w[0].as_usize();
+ let end_pos = w[1].as_usize();
+ let len = end_pos - start_pos;
+
+ if len != size as usize {
+ if cast_options.safe || array.is_null(idx) {
+ // Pad with nulls
+ if last_pos != start_pos {
+ mutable.extend(0, last_pos, start_pos);
+ }
+ mutable.extend_nulls(size as _);
+ nulls.as_mut().unwrap().set_bit(idx, false);
+ last_pos = end_pos
Review Comment:
If a section of values has `list_size + 1` elements, we would add nulls, and
then set `last_pos` to the end of that slice. I will add a commit explicitly
testing this and some more comments
--
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]