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

(arrow-rs) 01/01: fix: account for offset when building RunArray from ArrayData (#11660)

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

github-merge-queue[bot] pushed a commit to branch gh-readonly-queue/main/pr-11660-02499852223989da9dcd2419ae2fe9237407dc65
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git

commit 8a7cc3e27e4924cc411f7c4c14b72f798e74f88c
Author: Jeffrey Vo <je...@gmail.com>
AuthorDate: Mon Oct 19 16:26:07 2026 +0000

    fix: account for offset when building RunArray from ArrayData (#11660)
    
    # Which issue does this PR close?
    
    <!--
    It is not necessary to raise an issue, but it is encouraged if it is a
    non-trivial
    enhancement/bug.
    
    If this PR relates to an existing issue, but does not fully resolve it,
    please change
    the wording below from "Closes #NNN" to "Relates to #NNN" or "Part of
    #NNN" to avoid
    false closing an issue.
    -->
    
    None
    
    # Rationale for this change
    
    <!--
    Why are you proposing this change? If this is already explained clearly
    in the
    issue then this section is not needed. Explaining clearly why changes
    are proposed
    helps reviewers understand your changes and offer better suggestions for
    fixes.
    
    Please try to explain the problem you are trying to solve in terms of
    the user-visible
    behavior, rather than the implementation.
    -->
    
    Correctness issue when building run arrays from array data
    
    # What changes are included in this PR?
    
    <!--
    There is no need to duplicate the description in the issue here but it
    is
    sometimes worth providing a summary of the individual changes in this
    PR.
    -->
    
    Apply arraydata offset to run ends child array when constructing
    runarray from data
    
    # Are these changes tested?
    
    <!--
    We typically require tests for all PRs in order to:
    1. Prevent the code from being accidentally broken by subsequent changes
    2. Serve as another way to document the expected behavior of the code
    
    If tests are not included in your PR, please explain why (for example,
    are they
    covered by existing tests, if so identify these tests)?
    
    If this PR claims a performance improvement, please include evidence
    such as
    benchmark results.
    
    DO NOT simply paste a list of commands ran to verify the code; this is
    what our
    CI is for and it pollutes the PR. ONLY explain if testing was included
    with this
    PR, or why it wasn't.
    -->
    
    yes
    
    # Are there any significant user-facing changes?
    
    <!--
    Significant user-facing changes include:
    - Breaking public API change
    - Significant change to existing functionality (e.g. function returns
    something different)
    
    These need to be explicitly called out to ensure we have proper
    documentation if
    required and to ensure we follow proper semantic versioning.
    
    DO NOT restate the changes of this PR; if a bug was fixed and already
    explained
    above, we don't need this to be restated as a user-facing change.
    -->
    
    no
---
 arrow-array/src/array/run_array.rs | 43 +++++++++++++++++++++++++++++++++++---
 1 file changed, 40 insertions(+), 3 deletions(-)

diff --git a/arrow-array/src/array/run_array.rs b/arrow-array/src/array/run_array.rs
index e60234285d..6c64013865 100644
--- a/arrow-array/src/array/run_array.rs
+++ b/arrow-array/src/array/run_array.rs
@@ -426,9 +426,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();
@@ -436,7 +436,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);
@@ -870,6 +870,7 @@ mod tests {
     use rand::seq::SliceRandom;
 
     use super::*;
+    use crate::Float32Array;
     use crate::Int64Array;
     use crate::builder::PrimitiveRunBuilder;
     use crate::cast::AsArray;
@@ -1571,4 +1572,40 @@ 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(
+                Field::REE_RUN_ENDS_FIELD_DEFAULT_NAME,
+                DataType::Int32,
+                false,
+            )),
+            Arc::new(Field::new(
+                Field::REE_VALUES_FIELD_DEFAULT_NAME,
+                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);
+    }
 }