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

Function test_map_array_slice

arrow-array/src/array/map_array.rs:641–700  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

639 #[test]
640 #[ignore = "Test fails because slice of <list<struct>> is still buggy"]
641 fn test_map_array_slice() {
642 let map_array = create_from_buffers();
643
644 let sliced_array = map_array.slice(1, 2);
645 assert_eq!(2, sliced_array.len());
646 assert_eq!(1, sliced_array.offset());
647 let sliced_array_data = sliced_array.to_data();
648 for array_data in sliced_array_data.child_data() {
649 assert_eq!(array_data.offset(), 1);
650 }
651
652 // Check offset and length for each non-null value.
653 let sliced_map_array = sliced_array.as_any().downcast_ref::<MapArray>().unwrap();
654 assert_eq!(3, sliced_map_array.value_offsets()[0]);
655 assert_eq!(3, sliced_map_array.value_length(0));
656 assert_eq!(6, sliced_map_array.value_offsets()[1]);
657 assert_eq!(2, sliced_map_array.value_length(1));
658
659 // Construct key and values
660 let keys_data = ArrayData::builder(DataType::Int32)
661 .len(5)
662 .add_buffer(Buffer::from([3, 4, 5, 6, 7].to_byte_slice()))
663 .build()
664 .unwrap();
665 let values_data = ArrayData::builder(DataType::UInt32)
666 .len(5)
667 .add_buffer(Buffer::from([30u32, 40, 50, 60, 70].to_byte_slice()))
668 .build()
669 .unwrap();
670
671 // Construct a buffer for value offsets, for the nested array:
672 // [[3, 4, 5], [6, 7]]
673 let entry_offsets = Buffer::from([0, 3, 5].to_byte_slice());
674
675 let keys = Arc::new(Field::new("keys", DataType::Int32, false));
676 let values = Arc::new(Field::new("values", DataType::UInt32, false));
677 let entry_struct = StructArray::from(vec![
678 (keys, make_array(keys_data)),
679 (values, make_array(values_data)),
680 ]);
681
682 // Construct a map array from the above two
683 let map_data_type = DataType::Map(
684 Arc::new(Field::new(
685 "entries",
686 entry_struct.data_type().clone(),
687 false,
688 )),
689 false,
690 );
691 let expected_map_data = ArrayData::builder(map_data_type)
692 .len(2)
693 .add_buffer(entry_offsets)
694 .add_child_data(entry_struct.into_data())
695 .build()
696 .unwrap();
697 let expected_map_array = MapArray::from(expected_map_data);
698

Callers

nothing calls this directly

Calls 14

child_dataMethod · 0.80
add_bufferMethod · 0.80
to_byte_sliceMethod · 0.80
add_child_dataMethod · 0.80
create_from_buffersFunction · 0.70
MapClass · 0.50
sliceMethod · 0.45
to_dataMethod · 0.45
as_anyMethod · 0.45
buildMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected