gen_arr(4096, 128, 0.1, 0.1, true) will generate a StringViewArray with 4096 rows, each row containing a string with 128 random characters. around 10% of the rows are null, around 10% of the rows are non-ASCII.
(
n_rows: usize,
str_len_chars: usize,
null_density: f32,
utf8_density: f32,
is_string_view: bool, // false -> StringArray, true -> StringViewArray
)
| 25 | /// 4096 rows, each row containing a string with 128 random characters. |
| 26 | /// around 10% of the rows are null, around 10% of the rows are non-ASCII. |
| 27 | pub fn gen_string_array( |
| 28 | n_rows: usize, |
| 29 | str_len_chars: usize, |
| 30 | null_density: f32, |
| 31 | utf8_density: f32, |
| 32 | is_string_view: bool, // false -> StringArray, true -> StringViewArray |
| 33 | ) -> Vec<ColumnarValue> { |
| 34 | let mut rng = StdRng::seed_from_u64(42); |
| 35 | let rng_ref = &mut rng; |
| 36 | |
| 37 | let corpus = "DataFusionДатаФусион数据融合📊🔥"; // includes utf8 encoding with 1~4 bytes |
| 38 | let corpus = corpus.chars().collect::<Vec<_>>(); |
| 39 | |
| 40 | let mut output_string_vec: Vec<Option<String>> = Vec::with_capacity(n_rows); |
| 41 | for _ in 0..n_rows { |
| 42 | let rand_num = rng_ref.random::<f32>(); // [0.0, 1.0) |
| 43 | if rand_num < null_density { |
| 44 | output_string_vec.push(None); |
| 45 | } else if rand_num < null_density + utf8_density { |
| 46 | // Generate random UTF8 string |
| 47 | let mut generated_string = String::with_capacity(str_len_chars); |
| 48 | for _ in 0..str_len_chars { |
| 49 | let char = corpus[rng_ref.random_range(0..corpus.len())]; |
| 50 | generated_string.push(char); |
| 51 | } |
| 52 | output_string_vec.push(Some(generated_string)); |
| 53 | } else { |
| 54 | // Generate random ASCII-only string |
| 55 | let value = rng_ref |
| 56 | .sample_iter(&Alphanumeric) |
| 57 | .take(str_len_chars) |
| 58 | .collect(); |
| 59 | let value = String::from_utf8(value).unwrap(); |
| 60 | output_string_vec.push(Some(value)); |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | if is_string_view { |
| 65 | let string_view_array: StringViewArray = output_string_vec.into_iter().collect(); |
| 66 | vec![ColumnarValue::Array(Arc::new(string_view_array))] |
| 67 | } else { |
| 68 | let string_array: StringArray = output_string_vec.clone().into_iter().collect(); |
| 69 | vec![ColumnarValue::Array(Arc::new(string_array))] |
| 70 | } |
| 71 | } |
no test coverage detected
searching dependent graphs…