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

Function create_from_buffers

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

Source from the content-addressed store, hash-verified

487 use super::*;
488
489 fn create_from_buffers() -> MapArray {
490 // Construct key and values
491 let keys_data = ArrayData::builder(DataType::Int32)
492 .len(8)
493 .add_buffer(Buffer::from([0, 1, 2, 3, 4, 5, 6, 7].to_byte_slice()))
494 .build()
495 .unwrap();
496 let values_data = ArrayData::builder(DataType::UInt32)
497 .len(8)
498 .add_buffer(Buffer::from(
499 [0u32, 10, 20, 30, 40, 50, 60, 70].to_byte_slice(),
500 ))
501 .build()
502 .unwrap();
503
504 // Construct a buffer for value offsets, for the nested array:
505 // [[0, 1, 2], [3, 4, 5], [6, 7]]
506 let entry_offsets = Buffer::from([0, 3, 6, 8].to_byte_slice());
507
508 let keys = Arc::new(Field::new("keys", DataType::Int32, false));
509 let values = Arc::new(Field::new("values", DataType::UInt32, false));
510 let entry_struct = StructArray::from(vec![
511 (keys, make_array(keys_data)),
512 (values, make_array(values_data)),
513 ]);
514
515 // Construct a map array from the above two
516 let map_data_type = DataType::Map(
517 Arc::new(Field::new(
518 "entries",
519 entry_struct.data_type().clone(),
520 false,
521 )),
522 false,
523 );
524 let map_data = ArrayData::builder(map_data_type)
525 .len(3)
526 .add_buffer(entry_offsets)
527 .add_child_data(entry_struct.into_data())
528 .build()
529 .unwrap();
530 MapArray::from(map_data)
531 }
532
533 #[test]
534 fn test_map_array() {

Callers 2

test_map_array_sliceFunction · 0.70

Calls 9

add_bufferMethod · 0.80
to_byte_sliceMethod · 0.80
add_child_dataMethod · 0.80
MapClass · 0.50
buildMethod · 0.45
lenMethod · 0.45
cloneMethod · 0.45
data_typeMethod · 0.45
into_dataMethod · 0.45

Tested by 2

test_map_array_sliceFunction · 0.56