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

Function test_sparse_mixed

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

Source from the content-addressed store, hash-verified

1438
1439 #[test]
1440 fn test_sparse_mixed() {
1441 let mut builder = UnionBuilder::new_sparse();
1442 builder.append::<Int32Type>("a", 1).unwrap();
1443 builder.append::<Float64Type>("c", 3.0).unwrap();
1444 builder.append::<Int32Type>("a", 4).unwrap();
1445 builder.append::<Float64Type>("c", 5.0).unwrap();
1446 builder.append::<Int32Type>("a", 6).unwrap();
1447 let union = builder.build().unwrap();
1448
1449 let expected_type_ids = vec![0_i8, 1, 0, 1, 0];
1450
1451 // Check type ids
1452 assert_eq!(*union.type_ids(), expected_type_ids);
1453 for (i, id) in expected_type_ids.iter().enumerate() {
1454 assert_eq!(id, &union.type_id(i));
1455 }
1456
1457 // Check offsets, sparse union should only have a single buffer, i.e. no offsets
1458 assert!(union.offsets().is_none());
1459
1460 for i in 0..union.len() {
1461 let slot = union.value(i);
1462 assert!(!union.is_null(i));
1463 match i {
1464 0 => {
1465 let slot = slot.as_any().downcast_ref::<Int32Array>().unwrap();
1466 assert_eq!(slot.len(), 1);
1467 let value = slot.value(0);
1468 assert_eq!(1_i32, value);
1469 }
1470 1 => {
1471 let slot = slot.as_any().downcast_ref::<Float64Array>().unwrap();
1472 assert_eq!(slot.len(), 1);
1473 let value = slot.value(0);
1474 assert_eq!(value, 3_f64);
1475 }
1476 2 => {
1477 let slot = slot.as_any().downcast_ref::<Int32Array>().unwrap();
1478 assert_eq!(slot.len(), 1);
1479 let value = slot.value(0);
1480 assert_eq!(4_i32, value);
1481 }
1482 3 => {
1483 let slot = slot.as_any().downcast_ref::<Float64Array>().unwrap();
1484 assert_eq!(slot.len(), 1);
1485 let value = slot.value(0);
1486 assert_eq!(5_f64, value);
1487 }
1488 4 => {
1489 let slot = slot.as_any().downcast_ref::<Int32Array>().unwrap();
1490 assert_eq!(slot.len(), 1);
1491 let value = slot.value(0);
1492 assert_eq!(6_i32, value);
1493 }
1494 _ => unreachable!(),
1495 }
1496 }
1497 }

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