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-11536-ebd7a591d27aa6895aef7ff096795b03ffbee291
in repository https://gitbox.apache.org/repos/asf/arrow-rs.git

commit bfdcd26caebd331b928d3530097a97315af1442b
Author: Jeffrey Vo <[email protected]>
AuthorDate: Wed Oct 14 05:53:04 2026 +0000

    fix: account for arraydata offset when comparing runarrays (#11536)
    
    # 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.
    -->
    
    Equality fix for ArrayData
    
    # 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.
    -->
    
    If RunArray has physical offset for its runs child, we should account
    for this properly.
    
    # 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-data/src/equal/run.rs |  9 +++++++--
 arrow/tests/array_equal.rs  | 48 ++++++++++++++++++++++++++++++++++++++++++++-
 2 files changed, 54 insertions(+), 3 deletions(-)

diff --git a/arrow-data/src/equal/run.rs b/arrow-data/src/equal/run.rs
index 0032b56d1a..e54d0c8d74 100644
--- a/arrow-data/src/equal/run.rs
+++ b/arrow-data/src/equal/run.rs
@@ -18,6 +18,7 @@
 use crate::data::ArrayData;
 use arrow_buffer::ArrowNativeType;
 use arrow_buffer::RunEndBuffer;
+use arrow_buffer::ScalarBuffer;
 use arrow_schema::DataType;
 use num_traits::ToPrimitive;
 
@@ -63,8 +64,12 @@ impl<'a, T: ArrowNativeType + ToPrimitive> RunArrayData<'a, 
T> {
         // SAFETY: we're reconstructing RunEndBuffer from a known valid 
RunArray
         let run_ends = unsafe {
             RunEndBuffer::<T>::new_unchecked(
-                raw_run_ends_buffer.clone().into(),
-                run_ends_data.offset() + data.offset() + start,
+                ScalarBuffer::new(
+                    raw_run_ends_buffer.clone(),
+                    run_ends_data.offset(),
+                    run_ends_data.len(),
+                ),
+                data.offset() + start,
                 len,
             )
         };
diff --git a/arrow/tests/array_equal.rs b/arrow/tests/array_equal.rs
index cc45526a02..9ccd8dda3e 100644
--- a/arrow/tests/array_equal.rs
+++ b/arrow/tests/array_equal.rs
@@ -27,7 +27,8 @@ use arrow_array::builder::{
 };
 use arrow_array::cast::AsArray;
 use arrow_array::{
-    DictionaryArray, FixedSizeListArray, GenericListViewArray, PrimitiveArray, 
StringViewArray,
+    DictionaryArray, FixedSizeListArray, Float32Array, GenericListViewArray, 
PrimitiveArray,
+    RunArray, StringViewArray,
 };
 use arrow_buffer::{Buffer, ScalarBuffer, ToByteSlice};
 use arrow_data::{ArrayData, ArrayDataBuilder};
@@ -1541,3 +1542,48 @@ fn test_list_excess_children_equal() {
     assert_eq!(b.value_offsets(), &[0, 0, 2]);
     assert_eq!(a, b);
 }
+
+#[test]
+fn test_from_run_array_array_data_offset() {
+    let a = RunArray::try_new(
+        &Int32Array::from(vec![1, 3]),
+        &Float32Array::from(vec![1.5, 2.5]),
+    )
+    .unwrap()
+    .to_data();
+
+    // ensure if run_ends child has a physical offset, it is respected
+    // we construct & compare with ArrayData as other APIs will usually 
normalize
+    // this physical offset to 0
+    let b = {
+        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(3)
+            .offset(1)
+            .add_buffer(vec![-20_i32, 1_i32, 2, 4, 0].into())
+            .build()
+            .unwrap();
+        let values = Float32Array::from(vec![1.5, 2.5, 2.5]);
+
+        ArrayDataBuilder::new(dt)
+            .len(3)
+            .offset(0)
+            .child_data(vec![runs, values.to_data()])
+            .build()
+            .unwrap()
+    };
+
+    assert_eq!(a, b);
+}

Reply via email to