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

zeroshade pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/arrow-go.git


The following commit(s) were added to refs/heads/main by this push:
     new 588ca34c fix(array): compare sparse union slices at relative offsets 
(#1096)
588ca34c is described below

commit 588ca34c883df7c26b26f6fe94fb7ccaaf85598f
Author: Minh Vu <[email protected]>
AuthorDate: Thu Aug 6 18:31:07 2026 +0200

    fix(array): compare sparse union slices at relative offsets (#1096)
    
    SparseUnion.setData already slices each child using the parent union 
offset, so arraySparseUnionApproxEqual adding the offset again could compare 
the wrong child values or exceed slice bounds for offset-bearing slices. 
Compare each selected child at its relative i:i+1 position, matching the 
exact-equality path. Adds a regression test covering sparse-union 
approx-equality across slices with different offsets.
---
 arrow/array/union.go      |  4 ++--
 arrow/array/union_test.go | 33 +++++++++++++++++++++++++++++++++
 2 files changed, 35 insertions(+), 2 deletions(-)

diff --git a/arrow/array/union.go b/arrow/array/union.go
index 6329ea74..8b86947d 100644
--- a/arrow/array/union.go
+++ b/arrow/array/union.go
@@ -471,8 +471,8 @@ func arraySparseUnionApproxEqual(l, r *SparseUnion, opt 
equalOption) bool {
                }
 
                childNum := childIDs[typeID]
-               eq := sliceApproxEqual(l.children[childNum], 
int64(i+l.data.offset), int64(i+l.data.offset+1),
-                       r.children[childNum], int64(i+r.data.offset), 
int64(i+r.data.offset+1), opt)
+               eq := sliceApproxEqual(l.children[childNum], int64(i), 
int64(i+1),
+                       r.children[childNum], int64(i), int64(i+1), opt)
                if !eq {
                        return false
                }
diff --git a/arrow/array/union_test.go b/arrow/array/union_test.go
index fd234aad..7402f82b 100644
--- a/arrow/array/union_test.go
+++ b/arrow/array/union_test.go
@@ -25,6 +25,7 @@ import (
        "github.com/apache/arrow-go/v18/arrow/array"
        "github.com/apache/arrow-go/v18/arrow/memory"
        "github.com/stretchr/testify/assert"
+       "github.com/stretchr/testify/require"
        "github.com/stretchr/testify/suite"
 )
 
@@ -151,6 +152,38 @@ func TestUnionSliceEquals(t *testing.T) {
        checkUnion(batch.Column(1))
 }
 
+func TestSparseUnionApproxEqualSlicesWithDifferentOffsets(t *testing.T) {
+       mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
+       defer mem.AssertSize(t, 0)
+
+       leftChild, _, err := array.FromJSON(mem, arrow.PrimitiveTypes.Float64, 
strings.NewReader(`[0, 1, 2, 3, 4]`))
+       require.NoError(t, err)
+       defer leftChild.Release()
+       rightChild, _, err := array.FromJSON(mem, arrow.PrimitiveTypes.Float64, 
strings.NewReader(`[1, 2, 3, 4, 5]`))
+       require.NoError(t, err)
+       defer rightChild.Release()
+       leftIDs, _, err := array.FromJSON(mem, arrow.PrimitiveTypes.Int8, 
strings.NewReader(`[0, 0, 0, 0, 0]`))
+       require.NoError(t, err)
+       defer leftIDs.Release()
+       rightIDs, _, err := array.FromJSON(mem, arrow.PrimitiveTypes.Int8, 
strings.NewReader(`[0, 0, 0, 0, 0]`))
+       require.NoError(t, err)
+       defer rightIDs.Release()
+
+       left, err := array.NewSparseUnionFromArrays(leftIDs, 
[]arrow.Array{leftChild})
+       require.NoError(t, err)
+       defer left.Release()
+       right, err := array.NewSparseUnionFromArrays(rightIDs, 
[]arrow.Array{rightChild})
+       require.NoError(t, err)
+       defer right.Release()
+
+       leftSlice := array.NewSlice(left, 1, 3)
+       defer leftSlice.Release()
+       rightSlice := array.NewSlice(right, 0, 2)
+       defer rightSlice.Release()
+
+       assert.True(t, array.ApproxEqual(leftSlice, rightSlice))
+}
+
 func TestSparseUnionGetFlattenedField(t *testing.T) {
        mem := memory.NewCheckedAllocator(memory.DefaultAllocator)
        defer mem.AssertSize(t, 0)

Reply via email to