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 79d73d4d fix(arrow): reject duplicate union type codes (#1131)
79d73d4d is described below

commit 79d73d4de32620f642a97314a619164a016f62f8
Author: Minh Vu <[email protected]>
AuthorDate: Wed Aug 12 17:55:36 2026 +0200

    fix(arrow): reject duplicate union type codes (#1131)
    
    ### Rationale for this change
    
    Duplicate union type codes overwrite a child lookup entry during
    construction, leaving one child unreachable.
    
    ### What changes are included in this PR?
    
    Reject duplicate type codes during union validation and add coverage for
    both sparse and dense union types.
    
    ### Are these changes tested?
    
    - `go test ./arrow`
    
    ### Are there any user-facing changes?
    
    Union types with duplicate type codes are now rejected during
    construction instead of silently making one child unreachable.
---
 arrow/datatype_nested.go      |  5 +++++
 arrow/datatype_nested_test.go | 15 +++++++++++++++
 2 files changed, 20 insertions(+)

diff --git a/arrow/datatype_nested.go b/arrow/datatype_nested.go
index ae3b7f8d..6e92a1a9 100644
--- a/arrow/datatype_nested.go
+++ b/arrow/datatype_nested.go
@@ -734,10 +734,15 @@ func (t *unionType) validate(fields []Field, typeCodes 
[]UnionTypeCode, _ UnionM
                return errors.New("arrow: union types should have the same 
number of fields as type codes")
        }
 
+       var seen [int(MaxUnionTypeCode) + 1]bool
        for _, c := range typeCodes {
                if c < 0 || c > MaxUnionTypeCode {
                        return errors.New("arrow: union type code out of 
bounds")
                }
+               if seen[c] {
+                       return errors.New("arrow: union type codes must be 
unique")
+               }
+               seen[c] = true
        }
        return nil
 }
diff --git a/arrow/datatype_nested_test.go b/arrow/datatype_nested_test.go
index fc4c672c..b0d42b08 100644
--- a/arrow/datatype_nested_test.go
+++ b/arrow/datatype_nested_test.go
@@ -631,3 +631,18 @@ func TestFieldsImmutability(t *testing.T) {
                })
        }
 }
+
+func TestUnionRejectsDuplicateTypeCodes(t *testing.T) {
+       fields := []Field{
+               {Name: "a", Type: PrimitiveTypes.Int32},
+               {Name: "b", Type: PrimitiveTypes.Int32},
+       }
+       codes := []UnionTypeCode{1, 1}
+
+       assert.Panics(t, func() {
+               SparseUnionOf(fields, codes)
+       })
+       assert.Panics(t, func() {
+               DenseUnionOf(fields, codes)
+       })
+}

Reply via email to