alamb commented on a change in pull request #1248:
URL: https://github.com/apache/arrow-rs/pull/1248#discussion_r801998604
##########
File path: arrow/src/compute/kernels/filter.rs
##########
@@ -1298,4 +1347,141 @@ mod tests {
test_slices_fuzz(32, 8, 8);
test_slices_fuzz(32, 5, 9);
}
+
+ /// Filters `values` by `predicate` using standard rust iterators
+ fn filter_rust<T>(values: impl IntoIterator<Item = T>, predicate: &[bool])
-> Vec<T> {
+ values
+ .into_iter()
+ .zip(predicate)
+ .filter(|(_, x)| **x)
+ .map(|(a, _)| a)
+ .collect()
+ }
+
+ /// Generates an array of length `len` with `valid_percent` non-null values
+ fn gen_primitive<T>(len: usize, valid_percent: f64) -> Vec<Option<T>>
+ where
+ Standard: Distribution<T>,
+ {
+ let mut rng = thread_rng();
+ (0..len)
+ .map(|_| rng.gen_bool(valid_percent).then(|| rng.gen()))
+ .collect()
+ }
+
+ /// Generates an array of length `len` with `valid_percent` non-null values
+ fn gen_strings(
+ len: usize,
+ valid_percent: f64,
+ str_len_range: std::ops::Range<usize>,
+ ) -> Vec<Option<String>> {
+ let mut rng = thread_rng();
+ (0..len)
+ .map(|_| {
+ rng.gen_bool(valid_percent).then(|| {
+ let len = rng.gen_range(str_len_range.clone());
+ (0..len)
+ .map(|_| char::from(rng.sample(Alphanumeric)))
+ .collect()
+ })
+ })
+ .collect()
+ }
+
+ /// Returns an iterator that calls `Option::as_deref` on each item
+ fn as_deref<T: std::ops::Deref>(
+ src: &[Option<T>],
+ ) -> impl Iterator<Item = Option<&T::Target>> {
+ src.iter().map(|x| x.as_deref())
+ }
+
+ #[test]
+ fn fuzz_filter() {
+ let mut rng = thread_rng();
+
+ for i in 0..100 {
+ let filter_percent = match i {
+ 0..=4 => 1.,
+ 5..=10 => 0.,
Review comment:
TIL `match` works on ranges!
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]