This is an automated email from the ASF dual-hosted git repository.
Jefffrey pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/main by this push:
new 237aed5c8e Replace take_run BufferBuilders with Vec (#10631)
237aed5c8e is described below
commit 237aed5c8e4067e276ad2470d808e275c9697c31
Author: cakeni <[email protected]>
AuthorDate: Thu Aug 20 09:24:06 2026 +0800
Replace take_run BufferBuilders with Vec (#10631)
# Which issue does this PR close?
- Part of #10245.
# Rationale for this change
Using `Vec` instead of `BufferBuilder` can benefit from Rust's optimized
vector implementation. This updates the two builders used by the run-end
encoded take path.
# What changes are included in this PR?
- Replace the run-end and value-index `BufferBuilder` instances in
`take_run` with preallocated vectors.
- Push values directly and construct the final `ScalarBuffer` objects
from those vectors.
- Leave the unrelated fixed-size binary `BufferBuilder` path unchanged.
# Are these changes tested?
Yes. The following checks pass:
- `cargo +stable-x86_64-pc-windows-gnu fmt --all -- --check`
- `cargo +stable-x86_64-pc-windows-gnu clippy -p arrow-select
--all-targets --all-features --no-deps -- -D warnings`
- `cargo +stable-x86_64-pc-windows-gnu test -p arrow-select
--all-features` (406 unit tests and 17 doctests passed)
# Are there any user-facing changes?
No.
## AI assistance
OpenAI Codex assisted with code exploration and implementation drafting.
I reviewed the final behavior and diff.
Co-authored-by: Jeffrey Vo <[email protected]>
---
arrow-select/src/take.rs | 23 +++++++++--------------
1 file changed, 9 insertions(+), 14 deletions(-)
diff --git a/arrow-select/src/take.rs b/arrow-select/src/take.rs
index b3e9165caf..d86d888adc 100644
--- a/arrow-select/src/take.rs
+++ b/arrow-select/src/take.rs
@@ -952,11 +952,11 @@ fn take_run<T: RunEndIndexType, I: ArrowPrimitiveType>(
// get physical indices for the input logical indices
let physical_indices =
run_array.get_physical_indices(logical_indices.values())?;
- // Run encode the physical indices into new_run_ends_builder
+ // Run encode the physical indices into new_run_ends
// Keep track of the physical indices to take in take_value_indices
// `unwrap` is used in this function because the unwrapped values are
bounded by the corresponding `::Native`.
- let mut new_run_ends_builder = BufferBuilder::<T::Native>::new(1);
- let mut take_value_indices = BufferBuilder::<I::Native>::new(1);
+ let mut new_run_ends = Vec::with_capacity(1);
+ let mut take_value_indices = Vec::with_capacity(1);
let values_cmp = make_comparator(
run_array.values().as_ref(),
@@ -969,25 +969,20 @@ fn take_run<T: RunEndIndexType, I: ArrowPrimitiveType>(
let cur_idx = physical_indices[ix];
let is_new_run = cur_idx != prev_idx && values_cmp(cur_idx,
prev_idx).is_ne();
if is_new_run {
-
take_value_indices.append(I::Native::from_usize(prev_idx).unwrap());
- new_run_ends_builder.append(T::Native::from_usize(ix).unwrap());
+ take_value_indices.push(I::Native::from_usize(prev_idx).unwrap());
+ new_run_ends.push(T::Native::from_usize(ix).unwrap());
}
}
take_value_indices
- .append(I::Native::from_usize(physical_indices[physical_indices.len()
- 1]).unwrap());
-
new_run_ends_builder.append(T::Native::from_usize(physical_indices.len()).unwrap());
+ .push(I::Native::from_usize(physical_indices[physical_indices.len() -
1]).unwrap());
+ new_run_ends.push(T::Native::from_usize(physical_indices.len()).unwrap());
// SAFETY: run-ends are strictly increasing with last value == logical
length.
let run_ends = unsafe {
- RunEndBuffer::new_unchecked(
- ScalarBuffer::from(new_run_ends_builder.finish()),
- 0,
- physical_indices.len(),
- )
+ RunEndBuffer::new_unchecked(ScalarBuffer::from(new_run_ends), 0,
physical_indices.len())
};
- let take_value_indices =
-
PrimitiveArray::<I>::new(ScalarBuffer::from(take_value_indices.finish()), None);
+ let take_value_indices =
PrimitiveArray::<I>::new(ScalarBuffer::from(take_value_indices), None);
let new_values = take(run_array.values(), &take_value_indices, None)?;