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 7e537909 fix(array): support sparse union sliced type ids (#881)
7e537909 is described below

commit 7e537909f4d6f6160e075fe29cd8bd04283113ad
Author: Minh Vu <[email protected]>
AuthorDate: Thu Jul 2 19:01:58 2026 +0200

    fix(array): support sparse union sliced type ids (#881)
    
    Normalize the type-id value buffer to the input array's logical window 
before constructing sparse union data, so a sparse union can be built from 
sliced type ids without panicking when children are full logical length. The 
union is built at offset 0. Parity follow-up to #877.
---
 arrow/array/union.go      | 12 ++++++++++--
 arrow/array/union_test.go | 18 ++++++++++++++++++
 2 files changed, 28 insertions(+), 2 deletions(-)

diff --git a/arrow/array/union.go b/arrow/array/union.go
index f3159242..58524a76 100644
--- a/arrow/array/union.go
+++ b/arrow/array/union.go
@@ -289,7 +289,15 @@ func NewSparseUnionFromArraysWithFieldCodes(typeIDs 
arrow.Array, children []arro
                return nil, errors.New("arrow/array: type codes must have same 
length as children")
        }
 
-       buffers := []*memory.Buffer{nil, typeIDs.Data().Buffers()[1]}
+       typeIDBuffer := typeIDs.Data().Buffers()[1]
+       if typeIDBuffer != nil {
+               typeIDBuffer = memory.SliceBuffer(typeIDBuffer,
+                       arrow.Int8Traits.BytesRequired(typeIDs.Data().Offset()),
+                       arrow.Int8Traits.BytesRequired(typeIDs.Len()))
+               defer typeIDBuffer.Release()
+       }
+
+       buffers := []*memory.Buffer{nil, typeIDBuffer}
        ty := arrow.SparseUnionFromArrays(children, fields, codes)
 
        childData := make([]arrow.ArrayData, len(children))
@@ -300,7 +308,7 @@ func NewSparseUnionFromArraysWithFieldCodes(typeIDs 
arrow.Array, children []arro
                }
        }
 
-       data := NewData(ty, typeIDs.Len(), buffers, childData, 0, 
typeIDs.Data().Offset())
+       data := NewData(ty, typeIDs.Len(), buffers, childData, 0, 0)
        defer data.Release()
        return NewSparseUnionData(data), nil
 }
diff --git a/arrow/array/union_test.go b/arrow/array/union_test.go
index 7421b1bc..e20f0247 100644
--- a/arrow/array/union_test.go
+++ b/arrow/array/union_test.go
@@ -622,6 +622,24 @@ func (s *UnionFactorySuite) TestMakeSparse() {
                s.Error(result.ValidateFull())
        })
 
+       s.Run("sliced type ids", func() {
+               expected, err := array.NewSparseUnionFromArrays(s.typeIDs, 
children)
+               s.NoError(err)
+               defer expected.Release()
+
+               baseTypeIDs := s.typeidsFromSlice(3, 0, 1, 2, 0, 1, 3, 2, 0, 2, 
1)
+               defer baseTypeIDs.Release()
+               slicedTypeIDs := array.NewSlice(baseTypeIDs, 1, 
int64(baseTypeIDs.Len()))
+               defer slicedTypeIDs.Release()
+
+               result, err := array.NewSparseUnionFromArrays(slicedTypeIDs, 
children)
+               s.NoError(err)
+               defer result.Release()
+               s.Zero(result.Data().Offset())
+               s.NoError(result.ValidateFull())
+               s.True(array.Equal(expected, result))
+       })
+
        s.Run("invalid child length", func() {
                children[3], _, _ = array.FromJSON(s.mem, 
arrow.PrimitiveTypes.Int8,
                        strings.NewReader(`[0, 0, 0, 0, 0, -12, 0, 0, 0]`))

Reply via email to