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

Function create_string_view_array_with_len

arrow/src/util/bench_util.rs:417–450  ·  view source on GitHub ↗

Creates a random (but fixed-seeded) array of a given size, null density and length

(
    size: usize,
    null_density: f32,
    str_len: usize,
    mixed: bool,
)

Source from the content-addressed store, hash-verified

415
416/// Creates a random (but fixed-seeded) array of a given size, null density and length
417pub fn create_string_view_array_with_len(
418 size: usize,
419 null_density: f32,
420 str_len: usize,
421 mixed: bool,
422) -> StringViewArray {
423 let rng = &mut seedable_rng();
424
425 let mut lengths = Vec::with_capacity(size);
426
427 // if mixed, we creates first half that string length small than 12 bytes and second half large than 12 bytes
428 if mixed {
429 for _ in 0..size / 2 {
430 lengths.push(rng.random_range(1..12));
431 }
432 for _ in size / 2..size {
433 lengths.push(rng.random_range(12..=std::cmp::max(30, str_len)));
434 }
435 } else {
436 lengths.resize(size, str_len);
437 }
438
439 lengths
440 .into_iter()
441 .map(|len| {
442 if rng.random::<f32>() < null_density {
443 None
444 } else {
445 let value: Vec<u8> = rng.sample_iter(&Alphanumeric).take(len).collect();
446 Some(String::from_utf8(value).unwrap())
447 }
448 })
449 .collect()
450}
451
452/// Creates an random (but fixed-seeded) array of a given size and null density
453/// consisting of random 4 character alphanumeric strings

Callers 6

add_benchmarkFunction · 0.85
add_benchmarkFunction · 0.85
bench_iterFunction · 0.85
add_benchmarkFunction · 0.85
add_benchmarkFunction · 0.85
create_random_arrayFunction · 0.85

Calls 7

maxFunction · 0.85
collectMethod · 0.80
seedable_rngFunction · 0.70
pushMethod · 0.45
resizeMethod · 0.45
into_iterMethod · 0.45
takeMethod · 0.45

Tested by

no test coverage detected