| 1154 | |
| 1155 | #[test] |
| 1156 | fn test_extend_nulls_sparse_union() { |
| 1157 | let fields = UnionFields::try_new( |
| 1158 | vec![0, 1], |
| 1159 | vec![ |
| 1160 | Field::new("null", DataType::Null, true), |
| 1161 | Field::new("str", DataType::Utf8, true), |
| 1162 | ], |
| 1163 | ) |
| 1164 | .unwrap(); |
| 1165 | |
| 1166 | let type_ids = ScalarBuffer::from(vec![1i8]); |
| 1167 | let child_null = Arc::new(NullArray::new(1)) as ArrayRef; |
| 1168 | let child_str = Arc::new(StringArray::from(vec![Some("hello")])) as ArrayRef; |
| 1169 | let union_array = UnionArray::try_new( |
| 1170 | fields.clone(), |
| 1171 | type_ids, |
| 1172 | None, // sparse |
| 1173 | vec![child_null, child_str], |
| 1174 | ) |
| 1175 | .unwrap(); |
| 1176 | |
| 1177 | let data = union_array.to_data(); |
| 1178 | let mut mutable = MutableArrayData::new(vec![&data], true, 4); |
| 1179 | mutable.extend(0, 0, 1); // copy the first element |
| 1180 | mutable.extend_nulls(2); // add two nulls |
| 1181 | let result = mutable.freeze(); |
| 1182 | |
| 1183 | // Union arrays must not have a null bitmap per Arrow spec |
| 1184 | assert!(result.nulls().is_none()); |
| 1185 | |
| 1186 | let result_array = UnionArray::from(result); |
| 1187 | assert_eq!(result_array.len(), 3); |
| 1188 | // First element should be type_id 1 (str) |
| 1189 | assert_eq!(result_array.type_id(0), 1); |
| 1190 | // Null elements use the first type_id (0) |
| 1191 | assert_eq!(result_array.type_id(1), 0); |
| 1192 | assert_eq!(result_array.type_id(2), 0); |
| 1193 | // All children should have length 3 (sparse invariant) |
| 1194 | assert_eq!(result_array.child(0).len(), 3); |
| 1195 | assert_eq!(result_array.child(1).len(), 3); |
| 1196 | } |
| 1197 | |
| 1198 | #[test] |
| 1199 | fn test_extend_nulls_dense_union() { |