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 8c4a4bc01e [59_maintenance] fix: account for offset when building
RunArray from ArrayData (#11739)
8c4a4bc01e is described below
commit 8c4a4bc01e1fc1781e99ab5f52c40bab1bd42d74
Author: Andrew Lamb <[email protected]>
AuthorDate: Tue Oct 20 13:49:57 2026 -0400
[59_maintenance] fix: account for offset when building RunArray from
ArrayData (#11739)
- Backport https://github.com/apache/arrow-rs/pull/11660
- For inclusion in https://github.com/apache/arrow-rs/issues/11664
Cherry-pick of
https://github.com/apache/arrow-rs/commit/ee9f2a38f640f7147b2e849ea4fafa7f4333a45a
Note: the test uses literal `"run_ends"` / `"values"` field names
because `Field::REE_*_FIELD_DEFAULT_NAME` constants are not on the 59
line.
Co-authored-by: Jeffrey Vo <[email protected]>
---
arrow-array/src/array/run_array.rs | 35 ++++++++++++++++++++++++++++++++---
1 file changed, 32 insertions(+), 3 deletions(-)
diff --git a/arrow-array/src/array/run_array.rs
b/arrow-array/src/array/run_array.rs
index 9a56b01fca..6679bac810 100644
--- a/arrow-array/src/array/run_array.rs
+++ b/arrow-array/src/array/run_array.rs
@@ -374,9 +374,9 @@ impl<R: RunEndIndexType> From<ArrayData> for RunArray<R> {
// deconstruct the run ends child array
let (
run_end_data_type,
- _run_end_len,
+ run_end_len,
_run_end_nulls,
- _run_end_offset,
+ run_end_offset,
run_end_buffers,
_run_end_child_data,
) = run_end_child.into_parts();
@@ -384,7 +384,7 @@ impl<R: RunEndIndexType> From<ArrayData> for RunArray<R> {
let [run_end_buffer]: [arrow_buffer::Buffer; 1] = run_end_buffers
.try_into()
.expect("Run ends should have exactly one buffer");
- let scalar = ScalarBuffer::from(run_end_buffer);
+ let scalar = ScalarBuffer::new(run_end_buffer, run_end_offset,
run_end_len);
let run_ends = unsafe { RunEndBuffer::new_unchecked(scalar, offset,
len) };
let values = make_array(values_child);
@@ -818,6 +818,7 @@ mod tests {
use rand::seq::SliceRandom;
use super::*;
+ use crate::Float32Array;
use crate::Int64Array;
use crate::builder::PrimitiveRunBuilder;
use crate::cast::AsArray;
@@ -1519,4 +1520,32 @@ mod tests {
unsafe { RunArray::<Int32Type>::new_unchecked(dt, buffer, values)
};
assert_eq!(array, created_from_parts);
}
+
+ #[test]
+ fn test_from_array_data_offset() {
+ let dt = DataType::RunEndEncoded(
+ Arc::new(Field::new("run_ends", DataType::Int32, false)),
+ Arc::new(Field::new("values", DataType::Float32, true)),
+ );
+
+ let runs = ArrayData::builder(DataType::Int32)
+ .len(2)
+ .offset(2)
+ .add_buffer(vec![-10_i32, -20, 1_i32, 4, 0, 100].into())
+ .build()
+ .unwrap();
+ let values = Float32Array::from(vec![1.5, 2.5]);
+
+ let data = ArrayDataBuilder::new(dt)
+ .len(3)
+ .child_data(vec![runs, values.to_data()])
+ .build()
+ .unwrap();
+ let array = RunArray::<Int32Type>::from(data);
+ let array = array.downcast::<Float32Array>().unwrap();
+
+ assert_eq!(array.value(0), 1.5);
+ assert_eq!(array.value(1), 2.5);
+ assert_eq!(array.value(2), 2.5);
+ }
}