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

Function test_sparse_mixed_with_nulls

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

Source from the content-addressed store, hash-verified

1498
1499 #[test]
1500 fn test_sparse_mixed_with_nulls() {
1501 let mut builder = UnionBuilder::new_sparse();
1502 builder.append::<Int32Type>("a", 1).unwrap();
1503 builder.append_null::<Int32Type>("a").unwrap();
1504 builder.append::<Float64Type>("c", 3.0).unwrap();
1505 builder.append::<Int32Type>("a", 4).unwrap();
1506 let union = builder.build().unwrap();
1507
1508 let expected_type_ids = vec![0_i8, 0, 1, 0];
1509
1510 // Check type ids
1511 assert_eq!(*union.type_ids(), expected_type_ids);
1512 for (i, id) in expected_type_ids.iter().enumerate() {
1513 assert_eq!(id, &union.type_id(i));
1514 }
1515
1516 // Check offsets, sparse union should only have a single buffer, i.e. no offsets
1517 assert!(union.offsets().is_none());
1518
1519 for i in 0..union.len() {
1520 let slot = union.value(i);
1521 match i {
1522 0 => {
1523 let slot = slot.as_any().downcast_ref::<Int32Array>().unwrap();
1524 assert!(!slot.is_null(0));
1525 assert_eq!(slot.len(), 1);
1526 let value = slot.value(0);
1527 assert_eq!(1_i32, value);
1528 }
1529 1 => assert!(slot.is_null(0)),
1530 2 => {
1531 let slot = slot.as_any().downcast_ref::<Float64Array>().unwrap();
1532 assert!(!slot.is_null(0));
1533 assert_eq!(slot.len(), 1);
1534 let value = slot.value(0);
1535 assert_eq!(value, 3_f64);
1536 }
1537 3 => {
1538 let slot = slot.as_any().downcast_ref::<Int32Array>().unwrap();
1539 assert!(!slot.is_null(0));
1540 assert_eq!(slot.len(), 1);
1541 let value = slot.value(0);
1542 assert_eq!(4_i32, value);
1543 }
1544 _ => unreachable!(),
1545 }
1546 }
1547 }
1548
1549 #[test]
1550 fn test_sparse_mixed_with_nulls_and_offset() {

Callers

nothing calls this directly

Calls 5

buildMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
valueMethod · 0.45
as_anyMethod · 0.45

Tested by

no test coverage detected