Skip to content

Commit

Permalink
fix(data): map type ID to child index before indexing union child array
Browse files Browse the repository at this point in the history
  • Loading branch information
kawadakk committed Jul 31, 2023
1 parent 08f6afc commit abb5612
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions arrow-data/src/transform/union.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ pub(super) fn build_extend_sparse(array: &ArrayData) -> Extend {
pub(super) fn build_extend_dense(array: &ArrayData) -> Extend {
let type_ids = array.buffer::<i8>(0);
let offsets = array.buffer::<i32>(1);
let arrow_schema::DataType::Union(src_fields, _) = array.data_type() else {
unreachable!();
};

Box::new(
move |mutable: &mut _MutableArrayData, index: usize, start: usize, len: usize| {
Expand All @@ -48,14 +51,16 @@ pub(super) fn build_extend_dense(array: &ArrayData) -> Extend {
.extend_from_slice(&type_ids[start..start + len]);

(start..start + len).for_each(|i| {
let type_id = type_ids[i] as usize;
let type_id = type_ids[i];
let child_index =
src_fields.iter().position(|(r, _)| r == type_id).unwrap();
let src_offset = offsets[i] as usize;
let child_data = &mut mutable.child_data[type_id];
let child_data = &mut mutable.child_data[child_index];
let dst_offset = child_data.len();

// Extend offsets
mutable.buffer2.push(dst_offset as i32);
mutable.child_data[type_id].extend(index, src_offset, src_offset + 1)
mutable.child_data[child_index].extend(index, src_offset, src_offset + 1)
})
},
)
Expand Down

0 comments on commit abb5612

Please sign in to comment.