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

Function test_dense_i32

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

Source from the content-addressed store, hash-verified

1056
1057 #[test]
1058 fn test_dense_i32() {
1059 let mut builder = UnionBuilder::new_dense();
1060 builder.append::<Int32Type>("a", 1).unwrap();
1061 builder.append::<Int32Type>("b", 2).unwrap();
1062 builder.append::<Int32Type>("c", 3).unwrap();
1063 builder.append::<Int32Type>("a", 4).unwrap();
1064 builder.append::<Int32Type>("c", 5).unwrap();
1065 builder.append::<Int32Type>("a", 6).unwrap();
1066 builder.append::<Int32Type>("b", 7).unwrap();
1067 let union = builder.build().unwrap();
1068
1069 let expected_type_ids = vec![0_i8, 1, 2, 0, 2, 0, 1];
1070 let expected_offsets = vec![0_i32, 0, 0, 1, 1, 2, 1];
1071 let expected_array_values = [1_i32, 2, 3, 4, 5, 6, 7];
1072
1073 // Check type ids
1074 assert_eq!(*union.type_ids(), expected_type_ids);
1075 for (i, id) in expected_type_ids.iter().enumerate() {
1076 assert_eq!(id, &union.type_id(i));
1077 }
1078
1079 // Check offsets
1080 assert_eq!(*union.offsets().unwrap(), expected_offsets);
1081 for (i, id) in expected_offsets.iter().enumerate() {
1082 assert_eq!(union.value_offset(i), *id as usize);
1083 }
1084
1085 // Check data
1086 assert_eq!(
1087 *union.child(0).as_primitive::<Int32Type>().values(),
1088 [1_i32, 4, 6]
1089 );
1090 assert_eq!(
1091 *union.child(1).as_primitive::<Int32Type>().values(),
1092 [2_i32, 7]
1093 );
1094 assert_eq!(
1095 *union.child(2).as_primitive::<Int32Type>().values(),
1096 [3_i32, 5]
1097 );
1098
1099 assert_eq!(expected_array_values.len(), union.len());
1100 for (i, expected_value) in expected_array_values.iter().enumerate() {
1101 assert!(!union.is_null(i));
1102 let slot = union.value(i);
1103 let slot = slot.as_any().downcast_ref::<Int32Array>().unwrap();
1104 assert_eq!(slot.len(), 1);
1105 let value = slot.value(0);
1106 assert_eq!(expected_value, &value);
1107 }
1108 }
1109
1110 #[test]
1111 fn slice_union_array_single_field() {

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