1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use crate::prelude::*;
use rayon::prelude::*;
unsafe fn idx_to_str(idx: usize, arr: &Utf8Array<i64>) -> Option<&str> {
if arr.is_valid(idx) {
Some(arr.value_unchecked(idx))
} else {
None
}
}
impl Utf8Chunked {
pub fn par_iter_indexed(&self) -> impl IndexedParallelIterator<Item = Option<&str>> {
assert_eq!(self.chunks.len(), 1);
let arr = &*self.chunks[0];
let arr = unsafe { &*(arr as *const dyn Array as *const Utf8Array<i64>) };
(0..arr.len())
.into_par_iter()
.map(move |idx| unsafe { idx_to_str(idx, arr) })
}
pub fn par_iter(&self) -> impl ParallelIterator<Item = Option<&str>> + '_ {
self.chunks
.par_iter()
.map(move |arr| {
let arr = &**arr;
let arr = unsafe { &*(arr as *const dyn Array as *const Utf8Array<i64>) };
(0..arr.len())
.into_par_iter()
.map(move |idx| unsafe { idx_to_str(idx, arr) })
})
.flatten()
}
}