Creates a StringViewArray with random strings.
(&mut self)
| 65 | |
| 66 | /// Creates a StringViewArray with random strings. |
| 67 | pub fn gen_string_view(&mut self) -> ArrayRef { |
| 68 | let distinct_string_views: StringViewArray = (0..self.num_distinct_strings) |
| 69 | .map(|_| Some(random_string(&mut self.rng, self.max_len))) |
| 70 | .collect(); |
| 71 | |
| 72 | // pick num_strings randomly from the distinct string table |
| 73 | let indices: UInt32Array = (0..self.num_strings) |
| 74 | .map(|_| { |
| 75 | if self.rng.random::<f64>() < self.null_pct { |
| 76 | None |
| 77 | } else if self.num_distinct_strings > 1 { |
| 78 | let range = 1..(self.num_distinct_strings as u32); |
| 79 | Some(self.rng.random_range(range)) |
| 80 | } else { |
| 81 | Some(0) |
| 82 | } |
| 83 | }) |
| 84 | .collect(); |
| 85 | |
| 86 | let options = None; |
| 87 | arrow::compute::take(&distinct_string_views, &indices, options).unwrap() |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | /// Return a string of random characters of length 1..=max_len |