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

Function create_random_list_array

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

Source from the content-addressed store, hash-verified

297
298#[inline]
299fn create_random_list_array(
300 field: &Field,
301 size: usize,
302 null_density: f32,
303 true_density: f32,
304) -> Result<ArrayRef> {
305 // Override null density with 0.0 if the array is non-nullable
306 let list_null_density = match field.is_nullable() {
307 true => null_density,
308 false => 0.0,
309 };
310 let list_field;
311 let (offsets, child_len) = match field.data_type() {
312 DataType::List(f) => {
313 let (offsets, child_len) = create_random_offsets::<i32>(size, 0, 5);
314 list_field = f;
315 (Buffer::from(offsets.to_byte_slice()), child_len as usize)
316 }
317 DataType::LargeList(f) => {
318 let (offsets, child_len) = create_random_offsets::<i64>(size, 0, 5);
319 list_field = f;
320 (Buffer::from(offsets.to_byte_slice()), child_len as usize)
321 }
322 _ => {
323 return Err(ArrowError::InvalidArgumentError(format!(
324 "Cannot create list array for field {field}"
325 )));
326 }
327 };
328
329 // Create list's child data
330 let child_array = create_random_array(list_field, child_len, null_density, true_density)?;
331 let child_data = child_array.to_data();
332 // Create list's null buffers, if it is nullable
333 let null_buffer = match field.is_nullable() {
334 true => Some(create_random_null_buffer(size, list_null_density)),
335 false => None,
336 };
337 let list_data = unsafe {
338 ArrayData::new_unchecked(
339 field.data_type().clone(),
340 size,
341 None,
342 null_buffer,
343 0,
344 vec![offsets],
345 vec![child_data],
346 )
347 };
348 Ok(make_array(list_data))
349}
350
351#[inline]
352fn create_random_struct_array(

Callers 1

create_random_arrayFunction · 0.85

Calls 8

create_random_arrayFunction · 0.85
to_byte_sliceMethod · 0.80
make_arrayFunction · 0.50
is_nullableMethod · 0.45
data_typeMethod · 0.45
to_dataMethod · 0.45
cloneMethod · 0.45

Tested by

no test coverage detected