Dandandan commented on code in PR #2307:
URL: https://github.com/apache/arrow-rs/pull/2307#discussion_r937161928
##########
arrow/src/compute/kernels/take.rs:
##########
@@ -614,23 +614,41 @@ where
let mut output_buffer = MutableBuffer::new_null(len);
let output_slice = output_buffer.as_slice_mut();
- indices
- .iter()
- .enumerate()
- .try_for_each::<_, Result<()>>(|(i, index)| {
- if let Some(index) = index {
- let index = ToPrimitive::to_usize(&index).ok_or_else(|| {
+ let indices_has_nulls = indices.null_count() > 0;
+
+ if indices_has_nulls {
+ indices
+ .iter()
+ .enumerate()
+ .try_for_each::<_, Result<()>>(|(i, index)| {
+ if let Some(index) = index {
+ let index = ToPrimitive::to_usize(&index).ok_or_else(|| {
Review Comment:
Yeah, the pattern occurs quite often. Maybe we can at least reduce the
amount of `ok_or_else(|| {...` by having this function available (so it becomes
something like `let index = ToPrimitive::to_usize_or_error(&index)?;`
everywhere?
--
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]