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

Method flatten

arrow-array/src/array/struct_array.rs:376–409  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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
412impl From<ArrayData> for StructArray {

Callers 15

newMethod · 0.80
test_utf8_cast_offsetsFunction · 0.80
assert_castFunction · 0.80
test_list_format_optionsFunction · 0.80
poll_nextMethod · 0.80
test_catalogs_are_sortedFunction · 0.80

Calls 12

with_nullableMethod · 0.80
collectMethod · 0.80
make_arrayFunction · 0.70
fieldsMethod · 0.45
cloneMethod · 0.45
iterMethod · 0.45
is_nullableMethod · 0.45
as_refMethod · 0.45
nullsMethod · 0.45
into_builderMethod · 0.45
to_dataMethod · 0.45
build_uncheckedMethod · 0.45