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

Function create_random_struct_array

arrow/src/util/data_gen.rs:352–389  ·  view source on GitHub ↗
(
    field: &Field,
    size: usize,
    null_density: f32,
    true_density: f32,
)

Source from the content-addressed store, hash-verified

350
351#[inline]
352fn create_random_struct_array(
353 field: &Field,
354 size: usize,
355 null_density: f32,
356 true_density: f32,
357) -> Result<ArrayRef> {
358 let struct_fields = match field.data_type() {
359 DataType::Struct(fields) => fields,
360 _ => {
361 return Err(ArrowError::InvalidArgumentError(format!(
362 "Cannot create struct array for field {field}"
363 )));
364 }
365 };
366
367 let child_arrays = struct_fields
368 .iter()
369 .map(|struct_field| create_random_array(struct_field, size, null_density, true_density))
370 .collect::<Result<Vec<_>>>()?;
371
372 let null_buffer = match field.is_nullable() {
373 true => {
374 let nulls = arrow_buffer::BooleanBuffer::new(
375 create_random_null_buffer(size, null_density),
376 0,
377 size,
378 );
379 Some(nulls.into())
380 }
381 false => None,
382 };
383
384 Ok(Arc::new(StructArray::try_new(
385 struct_fields.clone(),
386 child_arrays,
387 null_buffer,
388 )?))
389}
390
391#[inline]
392fn create_random_map_array(

Callers 1

create_random_arrayFunction · 0.85

Calls 7

create_random_arrayFunction · 0.85
try_newFunction · 0.85
data_typeMethod · 0.45
iterMethod · 0.45
is_nullableMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected