Skip to content

Commit 460fd55

Browse files
authored
test: Add unit test for extending slice of list array (#5948)
* test: Add unit test for extending slice of list array * For review
1 parent 66bada5 commit 460fd55

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

arrow-array/src/ffi.rs

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1229,13 +1229,14 @@ mod tests_from_ffi {
12291229
use arrow_data::ArrayData;
12301230
use arrow_schema::{DataType, Field};
12311231

1232+
use crate::types::Int32Type;
12321233
use crate::{
12331234
array::{
12341235
Array, BooleanArray, DictionaryArray, FixedSizeBinaryArray, FixedSizeListArray,
12351236
Int32Array, Int64Array, StringArray, StructArray, UInt32Array, UInt64Array,
12361237
},
12371238
ffi::{from_ffi, FFI_ArrowArray, FFI_ArrowSchema},
1238-
make_array, ArrayRef,
1239+
make_array, ArrayRef, ListArray,
12391240
};
12401241

12411242
use super::{ImportedArrowArray, Result};
@@ -1514,4 +1515,40 @@ mod tests_from_ffi {
15141515
&imported
15151516
);
15161517
}
1518+
1519+
fn roundtrip_list_array(array: ListArray) -> ListArray {
1520+
let data = array.into_data();
1521+
1522+
let array = FFI_ArrowArray::new(&data);
1523+
let schema = FFI_ArrowSchema::try_from(data.data_type()).unwrap();
1524+
1525+
let array = unsafe { from_ffi(array, &schema) }.unwrap();
1526+
ListArray::from(array)
1527+
}
1528+
1529+
#[test]
1530+
fn test_extend_imported_list_slice() {
1531+
let mut data = vec![];
1532+
1533+
for i in 0..1000 {
1534+
let mut list = vec![];
1535+
for j in 0..100 {
1536+
list.push(Some(i * 1000 + j));
1537+
}
1538+
data.push(Some(list));
1539+
}
1540+
1541+
let list_array = ListArray::from_iter_primitive::<Int32Type, _, _>(data);
1542+
1543+
let slice = list_array.slice(500, 500);
1544+
let imported = roundtrip_list_array(slice.clone());
1545+
assert_eq!(imported.len(), 500);
1546+
assert_eq!(&slice, &imported);
1547+
1548+
let copied = extend_array(&imported);
1549+
assert_eq!(
1550+
copied.as_any().downcast_ref::<ListArray>().unwrap(),
1551+
&imported
1552+
);
1553+
}
15171554
}

0 commit comments

Comments
 (0)