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

Function test_sparse_i32

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

Source from the content-addressed store, hash-verified

1389
1390 #[test]
1391 fn test_sparse_i32() {
1392 let mut builder = UnionBuilder::new_sparse();
1393 builder.append::<Int32Type>("a", 1).unwrap();
1394 builder.append::<Int32Type>("b", 2).unwrap();
1395 builder.append::<Int32Type>("c", 3).unwrap();
1396 builder.append::<Int32Type>("a", 4).unwrap();
1397 builder.append::<Int32Type>("c", 5).unwrap();
1398 builder.append::<Int32Type>("a", 6).unwrap();
1399 builder.append::<Int32Type>("b", 7).unwrap();
1400 let union = builder.build().unwrap();
1401
1402 let expected_type_ids = vec![0_i8, 1, 2, 0, 2, 0, 1];
1403 let expected_array_values = [1_i32, 2, 3, 4, 5, 6, 7];
1404
1405 // Check type ids
1406 assert_eq!(*union.type_ids(), expected_type_ids);
1407 for (i, id) in expected_type_ids.iter().enumerate() {
1408 assert_eq!(id, &union.type_id(i));
1409 }
1410
1411 // Check offsets, sparse union should only have a single buffer
1412 assert!(union.offsets().is_none());
1413
1414 // Check data
1415 assert_eq!(
1416 *union.child(0).as_primitive::<Int32Type>().values(),
1417 [1_i32, 0, 0, 4, 0, 6, 0],
1418 );
1419 assert_eq!(
1420 *union.child(1).as_primitive::<Int32Type>().values(),
1421 [0_i32, 2_i32, 0, 0, 0, 0, 7]
1422 );
1423 assert_eq!(
1424 *union.child(2).as_primitive::<Int32Type>().values(),
1425 [0_i32, 0, 3_i32, 0, 5, 0, 0]
1426 );
1427
1428 assert_eq!(expected_array_values.len(), union.len());
1429 for (i, expected_value) in expected_array_values.iter().enumerate() {
1430 assert!(!union.is_null(i));
1431 let slot = union.value(i);
1432 let slot = slot.as_any().downcast_ref::<Int32Array>().unwrap();
1433 assert_eq!(slot.len(), 1);
1434 let value = slot.value(0);
1435 assert_eq!(expected_value, &value);
1436 }
1437 }
1438
1439 #[test]
1440 fn test_sparse_mixed() {

Callers

nothing calls this directly

Calls 4

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

Tested by

no test coverage detected