This is an automated email from the ASF dual-hosted git repository.
alamb pushed a commit to branch 59_maintenance
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git
The following commit(s) were added to refs/heads/59_maintenance by this push:
new 37e969f980 [59_maintenance] fix(arrow-array): `PrimitiveRunBuilder`
was buggy after `finish` (#11441)
37e969f980 is described below
commit 37e969f98069cda25d177aca3facad192864c5fc
Author: Jeffrey Vo <[email protected]>
AuthorDate: Fri Oct 9 03:20:52 2026 +0900
[59_maintenance] fix(arrow-array): `PrimitiveRunBuilder` was buggy after
`finish` (#11441)
- Backport https://github.com/apache/arrow-rs/pull/11326
- For inclusion in https://github.com/apache/arrow-rs/issues/11352
Cherry-pick of
https://github.com/apache/arrow-rs/commit/a5ba6a29d63671d4f8ef79f19b78257a8f19c70a
Co-authored-by: Neil Conway <[email protected]>
---
arrow-array/src/builder/primitive_run_builder.rs | 20 +++++++++++++++++++-
1 file changed, 19 insertions(+), 1 deletion(-)
diff --git a/arrow-array/src/builder/primitive_run_builder.rs
b/arrow-array/src/builder/primitive_run_builder.rs
index c1dc0d8d7d..17beffdffa 100644
--- a/arrow-array/src/builder/primitive_run_builder.rs
+++ b/arrow-array/src/builder/primitive_run_builder.rs
@@ -197,9 +197,10 @@ where
// write the last run end to the array.
self.append_run_end();
- // reset the run index to zero.
+ // reset the run indexes to zero.
self.current_value = None;
self.current_run_end_index = 0;
+ self.prev_run_end_index = 0;
// build the run encoded array by adding run_ends and values array as
its children.
let run_ends_array = self.run_ends_builder.finish();
@@ -327,6 +328,23 @@ mod tests {
);
}
+ #[test]
+ fn test_reuse_after_finish() {
+ let mut builder = PrimitiveRunBuilder::<Int16Type, Int16Type>::new();
+ builder.extend([1, 2, 3].into_iter().map(Some));
+ builder.finish();
+
+ // A single run with the same length as the previous batch
+ builder.extend([7, 7, 7].into_iter().map(Some));
+ let array = builder.finish();
+ assert_eq!(array.len(), 3);
+ assert_eq!(array.run_ends().values(), &[3]);
+ assert_eq!(array.values().as_primitive::<Int16Type>().values(), &[7]);
+
+ // Nothing appended since the last finish
+ assert_eq!(builder.finish().len(), 0);
+ }
+
#[test]
#[should_panic]
fn test_override_data_type_invalid() {