Skip to content

Commit

Permalink
fix fixed array
Browse files Browse the repository at this point in the history
  • Loading branch information
Kikkon committed Jun 16, 2024
1 parent 0913b30 commit 562dcfb
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions arrow-array/src/array/list_view_array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ use arrow_schema::{ArrowError, DataType, FieldRef};
use crate::array::{make_array, print_long_array};
use crate::iterator::GenericListViewArrayIter;
use crate::{
new_empty_array, Array, ArrayAccessor, ArrayRef, ArrowPrimitiveType, FixedSizeListArray,
new_empty_array, Array, ArrayAccessor, ArrayRef, FixedSizeListArray,
OffsetSizeTrait,
};

Expand Down Expand Up @@ -409,15 +409,13 @@ impl<OffsetSize: OffsetSizeTrait> From<FixedSizeListArray> for GenericListViewAr
DataType::FixedSizeList(f, size) => (f, *size as usize),
_ => unreachable!(),
};
let iter = std::iter::repeat(size).take(value.len());
let mut offsets = Vec::with_capacity(iter.size_hint().0);
offsets.push(OffsetSize::usize_as(0));
let mut offsets = Vec::with_capacity(size);
let mut acc = 0_usize;
let iter = std::iter::repeat(size).take(value.len());
let mut sizes = Vec::with_capacity(iter.size_hint().0);
for size in iter {
acc = acc.checked_add(size).expect("usize overflow");
offsets.push(OffsetSize::usize_as(acc));
acc = acc.checked_add(size).expect("usize overflow");
sizes.push(OffsetSize::usize_as(size));
}
OffsetSize::from_usize(acc).expect("offset overflow");
Expand Down Expand Up @@ -535,17 +533,13 @@ mod tests {
0,
list_array
.value(0)
.as_any()
.downcast_ref::<Int32Array>()
.unwrap()
.as_primitive::<Int32Type>()
.value(0)
);
assert_eq!(
0,
unsafe { list_array.value_unchecked(0) }
.as_any()
.downcast_ref::<Int32Array>()
.unwrap()
.as_primitive::<Int32Type>()
.value(0)
);
for i in 0..3 {
Expand Down Expand Up @@ -581,17 +575,13 @@ mod tests {
0,
list_array
.value(0)
.as_any()
.downcast_ref::<Int32Array>()
.unwrap()
.as_primitive::<Int32Type>()
.value(0)
);
assert_eq!(
0,
unsafe { list_array.value_unchecked(0) }
.as_any()
.downcast_ref::<Int32Array>()
.unwrap()
.as_primitive::<Int32Type>()
.value(0)
);
for i in 0..3 {
Expand Down Expand Up @@ -955,7 +945,15 @@ mod tests {
.iter()
.map(|x| x.map(|x| x.as_primitive::<Int32Type>().values().to_vec()))
.collect();
assert_eq!(values, vec![Some(vec![1, 2, 3]), None, Some(vec![4, 5, 6])])
assert_eq!(values, vec![Some(vec![1, 2, 3]), None, Some(vec![4, 5, 6])]);
let offsets = list.value_offsets();
assert_eq!(offsets, &[0, 3, 6]);
let sizes = list.value_sizes();
assert_eq!(sizes, &[3, 3, 3]);
}





}

0 comments on commit 562dcfb

Please sign in to comment.