()
| 789 | } |
| 790 | |
| 791 | fn test_generic_list<Offset: OffsetSizeTrait>() -> Result<()> { |
| 792 | // Construct a value array |
| 793 | let value_data = ArrayData::builder(DataType::Int32) |
| 794 | .len(8) |
| 795 | .add_buffer(Buffer::from_slice_ref([0, 1, 2, 3, 4, 5, 6, 7])) |
| 796 | .build() |
| 797 | .unwrap(); |
| 798 | |
| 799 | // Construct a buffer for value offsets, for the nested array: |
| 800 | // [[0, 1, 2], [3, 4, 5], [6, 7]] |
| 801 | let value_offsets = [0_usize, 3, 6, 8] |
| 802 | .iter() |
| 803 | .map(|i| Offset::from_usize(*i).unwrap()) |
| 804 | .collect::<Buffer>(); |
| 805 | |
| 806 | // Construct a list array from the above two |
| 807 | let list_data_type = GenericListArray::<Offset>::DATA_TYPE_CONSTRUCTOR(Arc::new( |
| 808 | Field::new_list_field(DataType::Int32, false), |
| 809 | )); |
| 810 | |
| 811 | let list_data = ArrayData::builder(list_data_type) |
| 812 | .len(3) |
| 813 | .add_buffer(value_offsets) |
| 814 | .add_child_data(value_data) |
| 815 | .build() |
| 816 | .unwrap(); |
| 817 | |
| 818 | // create an array natively |
| 819 | let array = GenericListArray::<Offset>::from(list_data.clone()); |
| 820 | |
| 821 | // export it |
| 822 | let (array, schema) = to_ffi(&array.to_data())?; |
| 823 | |
| 824 | // (simulate consumer) import it |
| 825 | let data = unsafe { from_ffi(array, &schema) }?; |
| 826 | let array = make_array(data); |
| 827 | |
| 828 | // downcast |
| 829 | let array = array |
| 830 | .as_any() |
| 831 | .downcast_ref::<GenericListArray<Offset>>() |
| 832 | .unwrap(); |
| 833 | |
| 834 | // verify |
| 835 | let expected = GenericListArray::<Offset>::from(list_data); |
| 836 | assert_eq!(&array.value(0), &expected.value(0)); |
| 837 | assert_eq!(&array.value(1), &expected.value(1)); |
| 838 | assert_eq!(&array.value(2), &expected.value(2)); |
| 839 | |
| 840 | // (drop/release) |
| 841 | Ok(()) |
| 842 | } |
| 843 | |
| 844 | #[test] |
| 845 | fn test_list() -> Result<()> { |
nothing calls this directly
no test coverage detected