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,
)
| 415 | |
| 416 | /// Creates a random (but fixed-seeded) array of a given size, null density and length |
| 417 | pub 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 |
no test coverage detected