westonpace commented on code in PR #7366: URL: https://github.com/apache/arrow-rs/pull/7366#discussion_r2026949053
########## arrow-array/src/array/struct_array.rs: ########## @@ -294,10 +294,34 @@ impl StructArray { impl From<ArrayData> for StructArray { fn from(data: ArrayData) -> Self { + let parent_offset = data.offset(); + let parent_len = data.len(); + let fields = data .child_data() .iter() - .map(|cd| make_array(cd.clone())) + .map(|cd| { + let child_offset = cd.offset(); + let child_len = cd.len(); + assert!( + child_len >= parent_len + parent_offset, + "struct array has offset {} and len {} but child array only has {} items", + parent_offset, + parent_len, + child_len + ); + // SAFETY: We have already checked that the child array has enough items and the + // only thing we are changing is the offset and length. As long as the child data + // was previously valid, then the new child data is also valid. + let cd = unsafe { + cd.clone() + .into_builder() + .offset(child_offset + parent_offset) Review Comment: We do not need to consider `child_offset`. The `child_len` is "number of items in the underlying array, after any `child_offset`. ########## arrow-array/src/array/struct_array.rs: ########## @@ -294,10 +294,34 @@ impl StructArray { impl From<ArrayData> for StructArray { fn from(data: ArrayData) -> Self { + let parent_offset = data.offset(); + let parent_len = data.len(); + let fields = data .child_data() .iter() - .map(|cd| make_array(cd.clone())) + .map(|cd| { + let child_offset = cd.offset(); + let child_len = cd.len(); + assert!( + child_len >= parent_len + parent_offset, + "struct array has offset {} and len {} but child array only has {} items", + parent_offset, + parent_len, + child_len + ); + // SAFETY: We have already checked that the child array has enough items and the + // only thing we are changing is the offset and length. As long as the child data + // was previously valid, then the new child data is also valid. + let cd = unsafe { + cd.clone() + .into_builder() + .offset(child_offset + parent_offset) Review Comment: We do not need to consider `child_offset`. The `child_len` is "number of items in the underlying array, after any `child_offset`." -- 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: github-unsubscr...@arrow.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org