-
Notifications
You must be signed in to change notification settings - Fork 1.7k
minor: refactor array reverse internals #18445
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
| fn general_array_reverse<O: OffsetSizeTrait + TryFrom<i64>>( | ||
| fn general_array_reverse<O: OffsetSizeTrait>( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unused trait bound
| OffsetBuffer::<O>::new(offsets.into()), | ||
| arrow::array::make_array(data), | ||
| Some(nulls.into()), | ||
| array.nulls().cloned(), |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can directly copy the nulls from the input array instead of recreating it step by step (do the same for fixed size lists below)
| MutableArrayData::with_capacities(vec![&original_data], false, capacity); | ||
|
|
||
| for (row_index, offset_window) in array.offsets().windows(2).enumerate() { | ||
| for (row_index, (&start, &end)) in array.offsets().iter().tuple_windows().enumerate() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Using tuple_windows from itertools for a nicer interface on grabbing the start & end indices
| nulls.push(false); | ||
| offsets.push(offsets[row_index] + O::one()); | ||
| mutable.extend(0, 0, 1); | ||
| offsets.push(offsets[row_index]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We can just have an empty list here since it's null anyway, instead of extending the child array by one element
| let end = offset_window[1]; | ||
|
|
||
| let mut index = end - O::one(); | ||
| let mut cnt = 0; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
cnt can be determined once up front
|
Nice! |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nice little cleanup!
Which issue does this PR close?
N/A
Rationale for this change
When reviewing #18424 I noticed some refactoring that could be applied to existing array reverse implementation.
What changes are included in this PR?
Are these changes tested?
See my comments for the refactors & justifications.
Existing tests.
Are there any user-facing changes?
No.