Returns the children of this [`StructArray`] with the struct's validity bitmap AND'd into each child's validity bitmap. This ensures that positions where the struct itself is null are also null in each returned child array. Fields that were non-nullable are marked nullable in the returned [`Fields`] when the struct has nulls. If the struct has no nulls, children and fields are returned as-is. T
(&self)
| 374 | /// assert!(columns[0].is_null(1)); |
| 375 | /// ``` |
| 376 | pub fn flatten(&self) -> (Fields, Vec<ArrayRef>) { |
| 377 | let schema_fields = self.fields(); |
| 378 | |
| 379 | let struct_nulls = match &self.nulls { |
| 380 | Some(n) => n, |
| 381 | None => return (schema_fields.clone(), self.fields.clone()), |
| 382 | }; |
| 383 | |
| 384 | let new_fields: Fields = schema_fields |
| 385 | .iter() |
| 386 | .map(|f| { |
| 387 | if f.is_nullable() { |
| 388 | Arc::clone(f) |
| 389 | } else { |
| 390 | Arc::new(f.as_ref().clone().with_nullable(true)) |
| 391 | } |
| 392 | }) |
| 393 | .collect::<Vec<_>>() |
| 394 | .into(); |
| 395 | |
| 396 | let new_columns = self |
| 397 | .fields |
| 398 | .iter() |
| 399 | .map(|child| { |
| 400 | let merged = NullBuffer::union(Some(struct_nulls), child.nulls()); |
| 401 | // SAFETY: We only make the null buffer more restrictive (adding nulls). |
| 402 | // All data buffers and child data remain unchanged. |
| 403 | let data = child.to_data().into_builder().nulls(merged); |
| 404 | make_array(unsafe { data.build_unchecked() }) |
| 405 | }) |
| 406 | .collect(); |
| 407 | |
| 408 | (new_fields, new_columns) |
| 409 | } |
| 410 | } |
| 411 | |
| 412 | impl From<ArrayData> for StructArray { |