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

Function test_union_dense_array

arrow-array/src/ffi.rs:1322–1377  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

1320
1321 #[test]
1322 fn test_union_dense_array() -> Result<()> {
1323 let mut builder = UnionBuilder::new_dense();
1324 builder.append::<Int32Type>("a", 1).unwrap();
1325 builder.append_null::<Int32Type>("a").unwrap();
1326 builder.append::<Float64Type>("c", 3.0).unwrap();
1327 builder.append::<Int32Type>("a", 4).unwrap();
1328 let union = builder.build().unwrap();
1329
1330 // export it
1331 let (array, schema) = to_ffi(&union.to_data())?;
1332
1333 // (simulate consumer) import it
1334 let data = unsafe { from_ffi(array, &schema) }?;
1335 let array = UnionArray::from(data);
1336
1337 let expected_type_ids = vec![0_i8, 0, 1, 0];
1338
1339 // Check type ids
1340 assert_eq!(*array.type_ids(), expected_type_ids);
1341 for (i, id) in expected_type_ids.iter().enumerate() {
1342 assert_eq!(id, &array.type_id(i));
1343 }
1344
1345 assert!(array.offsets().is_some());
1346
1347 for i in 0..array.len() {
1348 let slot = array.value(i);
1349 match i {
1350 0 => {
1351 let slot = slot.as_primitive::<Int32Type>();
1352 assert!(!slot.is_null(0));
1353 assert_eq!(slot.len(), 1);
1354 let value = slot.value(0);
1355 assert_eq!(1_i32, value);
1356 }
1357 1 => assert!(slot.is_null(0)),
1358 2 => {
1359 let slot = slot.as_primitive::<Float64Type>();
1360 assert!(!slot.is_null(0));
1361 assert_eq!(slot.len(), 1);
1362 let value = slot.value(0);
1363 assert_eq!(value, 3_f64);
1364 }
1365 3 => {
1366 let slot = slot.as_primitive::<Int32Type>();
1367 assert!(!slot.is_null(0));
1368 assert_eq!(slot.len(), 1);
1369 let value = slot.value(0);
1370 assert_eq!(4_i32, value);
1371 }
1372 _ => unreachable!(),
1373 }
1374 }
1375
1376 Ok(())
1377 }
1378
1379 #[test]

Callers

nothing calls this directly

Calls 7

to_ffiFunction · 0.85
from_ffiFunction · 0.85
buildMethod · 0.45
to_dataMethod · 0.45
iterMethod · 0.45
lenMethod · 0.45
valueMethod · 0.45

Tested by

no test coverage detected