MCPcopy Create free account
hub / github.com/apache/arrow-rs / test_generic_list_view

Function test_generic_list_view

arrow-array/src/ffi.rs:854–907  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

852 }
853
854 fn test_generic_list_view<Offset: OffsetSizeTrait + ArrowNativeType>() -> Result<()> {
855 // Construct a value array
856 let value_data = ArrayData::builder(DataType::Int16)
857 .len(8)
858 .add_buffer(Buffer::from_slice_ref([0_i16, 1, 2, 3, 4, 5, 6, 7]))
859 .build()
860 .unwrap();
861
862 // Construct a buffer for value offsets, for the nested array:
863 // [[0, 1, 2], [3, 4, 5], [6, 7]]
864 let value_offsets = [0_usize, 3, 6]
865 .iter()
866 .map(|i| Offset::from_usize(*i).unwrap())
867 .collect::<Buffer>();
868
869 let sizes_buffer = [3_usize, 3, 2]
870 .iter()
871 .map(|i| Offset::from_usize(*i).unwrap())
872 .collect::<Buffer>();
873
874 // Construct a list array from the above two
875 let list_view_dt = GenericListViewArray::<Offset>::DATA_TYPE_CONSTRUCTOR(Arc::new(
876 Field::new_list_field(DataType::Int16, false),
877 ));
878
879 let list_data = ArrayData::builder(list_view_dt)
880 .len(3)
881 .add_buffer(value_offsets)
882 .add_buffer(sizes_buffer)
883 .add_child_data(value_data)
884 .build()
885 .unwrap();
886
887 let original = GenericListViewArray::<Offset>::from(list_data.clone());
888
889 // export it
890 let (array, schema) = to_ffi(&original.to_data())?;
891
892 // (simulate consumer) import it
893 let data = unsafe { from_ffi(array, &schema) }?;
894 let array = make_array(data);
895
896 // downcast
897 let array = array
898 .as_any()
899 .downcast_ref::<GenericListViewArray<Offset>>()
900 .unwrap();
901
902 assert_eq!(&array.value(0), &original.value(0));
903 assert_eq!(&array.value(1), &original.value(1));
904 assert_eq!(&array.value(2), &original.value(2));
905
906 Ok(())
907 }
908
909 #[test]
910 fn test_list_view() -> Result<()> {

Callers

nothing calls this directly

Calls 11

to_ffiFunction · 0.85
from_ffiFunction · 0.85
add_bufferMethod · 0.80
add_child_dataMethod · 0.80
make_arrayFunction · 0.50
buildMethod · 0.45
lenMethod · 0.45
iterMethod · 0.45
cloneMethod · 0.45
to_dataMethod · 0.45
as_anyMethod · 0.45

Tested by

no test coverage detected