Dandandan commented on code in PR #9625:
URL: https://github.com/apache/arrow-rs/pull/9625#discussion_r3009261282
##########
arrow-select/src/take.rs:
##########
@@ -499,95 +535,71 @@ fn take_bytes<T: ByteArrayType, IndexType:
ArrowPrimitiveType>(
offsets.push(T::Offset::default());
let input_offsets = array.value_offsets();
+ let input_values = array.value_data();
let mut capacity = 0;
let nulls = take_nulls(array.nulls(), indices);
- let (offsets, values) = if array.null_count() == 0 && indices.null_count()
== 0 {
- offsets.reserve(indices.len());
- for index in indices.values() {
- let index = index.as_usize();
- capacity += input_offsets[index + 1].as_usize() -
input_offsets[index].as_usize();
- offsets.push(
- T::Offset::from_usize(capacity)
- .ok_or_else(|| ArrowError::OffsetOverflowError(capacity))?,
- );
- }
- let mut values = Vec::with_capacity(capacity);
-
- for index in indices.values() {
- values.extend_from_slice(array.value(index.as_usize()).as_ref());
- }
- (offsets, values)
- } else if indices.null_count() == 0 {
- offsets.reserve(indices.len());
- for index in indices.values() {
- let index = index.as_usize();
- if array.is_valid(index) {
- capacity += input_offsets[index + 1].as_usize() -
input_offsets[index].as_usize();
+ // Pass 1: compute offsets and collect byte ranges.
+ // Branch on output nulls — `None` means every output slot is valid.
+ let ranges = match nulls.as_ref().filter(|n| n.null_count() > 0) {
+ // Fast path: no nulls in output, every index is valid.
+ None => {
+ let mut ranges = Vec::with_capacity(indices.len());
+ for index in indices.values() {
+ let index = index.as_usize();
+ let start = input_offsets[index].as_usize();
+ let end = input_offsets[index + 1].as_usize();
+ capacity += end - start;
+ offsets.push(
+ T::Offset::from_usize(capacity)
+ .ok_or_else(||
ArrowError::OffsetOverflowError(capacity))?,
+ );
+ ranges.push((start, end));
Review Comment:
Won't for this case be faster to just keep the previous implementation?
--
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]