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

Function slice_union_array

arrow-array/src/array/union_array.rs:1634–1696  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1632
1633 #[test]
1634 fn slice_union_array() {
1635 // [1, null, 3.0, null, 4]
1636 fn create_union(mut builder: UnionBuilder) -> UnionArray {
1637 builder.append::<Int32Type>("a", 1).unwrap();
1638 builder.append_null::<Int32Type>("a").unwrap();
1639 builder.append::<Float64Type>("c", 3.0).unwrap();
1640 builder.append_null::<Float64Type>("c").unwrap();
1641 builder.append::<Int32Type>("a", 4).unwrap();
1642 builder.build().unwrap()
1643 }
1644
1645 fn create_batch(union: UnionArray) -> RecordBatch {
1646 let schema = Schema::new(vec![Field::new(
1647 "struct_array",
1648 union.data_type().clone(),
1649 true,
1650 )]);
1651
1652 RecordBatch::try_new(Arc::new(schema), vec![Arc::new(union)]).unwrap()
1653 }
1654
1655 fn test_slice_union(record_batch_slice: RecordBatch) {
1656 let union_slice = record_batch_slice
1657 .column(0)
1658 .as_any()
1659 .downcast_ref::<UnionArray>()
1660 .unwrap();
1661
1662 assert_eq!(union_slice.type_id(0), 0);
1663 assert_eq!(union_slice.type_id(1), 1);
1664 assert_eq!(union_slice.type_id(2), 1);
1665
1666 let slot = union_slice.value(0);
1667 let array = slot.as_primitive::<Int32Type>();
1668 assert_eq!(array.len(), 1);
1669 assert!(array.is_null(0));
1670
1671 let slot = union_slice.value(1);
1672 let array = slot.as_primitive::<Float64Type>();
1673 assert_eq!(array.len(), 1);
1674 assert!(array.is_valid(0));
1675 assert_eq!(array.value(0), 3.0);
1676
1677 let slot = union_slice.value(2);
1678 let array = slot.as_primitive::<Float64Type>();
1679 assert_eq!(array.len(), 1);
1680 assert!(array.is_null(0));
1681 }
1682
1683 // Sparse Union
1684 let builder = UnionBuilder::new_sparse();
1685 let record_batch = create_batch(create_union(builder));
1686 // [null, 3.0, null]
1687 let record_batch_slice = record_batch.slice(1, 3);
1688 test_slice_union(record_batch_slice);
1689
1690 // Dense Union
1691 let builder = UnionBuilder::new_dense();

Callers

nothing calls this directly

Calls 4

create_unionFunction · 0.85
test_slice_unionFunction · 0.85
create_batchFunction · 0.70
sliceMethod · 0.45

Tested by

no test coverage detected