MCPcopy Create free account
hub / github.com/apache/datafusion / gen_string_array

Function gen_string_array

datafusion/functions/benches/split_part.rs:35–65  ·  view source on GitHub ↗

Creates an array of strings with `num_parts` random alphanumeric segments of `part_len` bytes each, joined by `delimiter`.

(
    n_rows: usize,
    num_parts: usize,
    part_len: usize,
    delimiter: &str,
    use_string_view: bool,
)

Source from the content-addressed store, hash-verified

33/// Creates an array of strings with `num_parts` random alphanumeric segments
34/// of `part_len` bytes each, joined by `delimiter`.
35fn gen_string_array(
36 n_rows: usize,
37 num_parts: usize,
38 part_len: usize,
39 delimiter: &str,
40 use_string_view: bool,
41) -> ColumnarValue {
42 let mut rng = StdRng::seed_from_u64(42);
43
44 let mut strings: Vec<String> = Vec::with_capacity(n_rows);
45 for _ in 0..n_rows {
46 let mut parts: Vec<String> = Vec::with_capacity(num_parts);
47 for _ in 0..num_parts {
48 let part: String = (&mut rng)
49 .sample_iter(&Alphanumeric)
50 .take(part_len)
51 .map(char::from)
52 .collect();
53 parts.push(part);
54 }
55 strings.push(parts.join(delimiter));
56 }
57
58 if use_string_view {
59 let string_array: StringViewArray = strings.into_iter().map(Some).collect();
60 ColumnarValue::Array(Arc::new(string_array) as ArrayRef)
61 } else {
62 let string_array: StringArray = strings.into_iter().map(Some).collect();
63 ColumnarValue::Array(Arc::new(string_array) as ArrayRef)
64 }
65}
66
67#[expect(clippy::too_many_arguments)]
68fn bench_split_part(

Callers 1

criterion_benchmarkFunction · 0.70

Calls 7

newFunction · 0.85
collectMethod · 0.80
mapMethod · 0.45
takeMethod · 0.45
pushMethod · 0.45
joinMethod · 0.45
into_iterMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…