You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@arrow.apache.org by al...@apache.org on 2026/10/21 19:27:12 UTC

(arrow-rs) branch 58_maintenance updated: [58_maintenance] fix: account for offset when building RunArray from ArrayData (#11766)

This is an automated email from the ASF dual-hosted git repository.

alamb pushed a commit to branch 58_maintenance
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git


The following commit(s) were added to refs/heads/58_maintenance by this push:
     new 6ef63e1049 [58_maintenance] fix: account for offset when building RunArray from ArrayData (#11766)
6ef63e1049 is described below

commit 6ef63e1049f9ba891bc0d9fd8b4adbaeacc1c6ae
Author: Jeffrey Vo <je...@gmail.com>
AuthorDate: Thu Oct 22 04:27:04 2026 +0900

    [58_maintenance] fix: account for offset when building RunArray from ArrayData (#11766)
    
    - Backport https://github.com/apache/arrow-rs/pull/11660
    - For inclusion in https://github.com/apache/arrow-rs/issues/11665
    
    Cherry-pick of
    https://github.com/apache/arrow-rs/commit/ee9f2a38f640f7147b2e849ea4fafa7f4333a45a
---
 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 02bc730b32..f12c5eebc4 100644
--- a/arrow-array/src/array/run_array.rs
+++ b/arrow-array/src/array/run_array.rs
@@ -367,9 +367,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();
@@ -377,7 +377,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);
@@ -789,6 +789,7 @@ mod tests {
     use rand::seq::SliceRandom;
 
     use super::*;
+    use crate::Float32Array;
     use crate::builder::PrimitiveRunBuilder;
     use crate::cast::AsArray;
     use crate::new_empty_array;
@@ -1470,4 +1471,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);
+    }
 }