jhorstmann commented on code in PR #8849:
URL: https://github.com/apache/arrow-rs/pull/8849#discussion_r2533602341
##########
arrow-select/src/take.rs:
##########
@@ -422,9 +422,10 @@ fn take_native<T: ArrowNativeType, I: ArrowPrimitiveType>(
.enumerate()
.map(|(idx, index)| match values.get(index.as_usize()) {
Some(v) => *v,
- None => match n.is_null(idx) {
- true => T::default(),
- false => panic!("Out-of-bounds index {index:?}"),
+ // SAFETY: idx<indices.len()
+ None => match unsafe { n.inner().value_unchecked(idx) } {
+ false => T::default(),
Review Comment:
Logic looks correct to me, but is not really intuitive. In our
microbenchmarks the current code might faster because it avoids a branch on the
validity bit in the happy case, but I'm not sure that will still be faster on
larger inputs, or if a larger amount of indices is null.
I would find the following more intuitive, and hopefully not much slower
(slice, range and zip iteration should all be TrustedLen):
```rust
indices
.values()
.iter()
.zip((0..n.len()).map(move |i| unsafe {
n.inner().value_unchecked(i) }))
.map(|(index, valid)| if valid {
values[index.as_usize()]
} else {
T::default()
})
.collect()
```
--
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]