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

Function create_string_array_for_runs

arrow/src/util/bench_util.rs:628–658  ·  view source on GitHub ↗

Create string array to be used by run array builder. The string array will result in run array with physical length of `physical_array_len` and logical length of `logical_array_len`

(
    physical_array_len: usize,
    logical_array_len: usize,
    string_len: usize,
)

Source from the content-addressed store, hash-verified

626/// will result in run array with physical length of `physical_array_len`
627/// and logical length of `logical_array_len`
628pub fn create_string_array_for_runs(
629 physical_array_len: usize,
630 logical_array_len: usize,
631 string_len: usize,
632) -> Vec<String> {
633 assert!(logical_array_len >= physical_array_len);
634 let mut rng = rng();
635
636 // typical length of each run
637 let run_len = logical_array_len / physical_array_len;
638
639 // Some runs should have extra length
640 let mut run_len_extra = logical_array_len % physical_array_len;
641
642 let mut values: Vec<String> = (0..physical_array_len)
643 .map(|_| (0..string_len).map(|_| rng.random::<char>()).collect())
644 .flat_map(|s| {
645 let mut take_len = run_len;
646 if run_len_extra > 0 {
647 take_len += 1;
648 run_len_extra -= 1;
649 }
650 std::iter::repeat_n(s, take_len)
651 })
652 .collect();
653 while values.len() < logical_array_len {
654 let last_val = values[values.len() - 1].clone();
655 values.push(last_val);
656 }
657 values
658}
659
660/// Creates an random (but fixed-seeded) binary array of a given size and null density
661pub fn create_binary_array<Offset: OffsetSizeTrait>(

Callers 1

criterion_benchmarkFunction · 0.85

Calls 4

collectMethod · 0.80
lenMethod · 0.45
cloneMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected