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 83f369ca fix(arrow/array): validate extension arrays by their storage
type (#1487)
83f369ca is described below
commit 83f369ca8d5cc0097d14db117c8bbd05ac11394a
Author: Harrison Crosse <[email protected]>
AuthorDate: Mon Nov 9 12:26:17 2026 -0500
fix(arrow/array): validate extension arrays by their storage type (#1487)
### Rationale for this change
`Validate` rejects valid extension arrays over union and dictionary
storage, while `ValidateFull` also rejects null storage.
### What changes are included in this PR?
Validation now uses storage types for null counts, union layout,
dictionary checks and the existing run-end encoded check, matching
[C++](https://github.com/apache/arrow/blob/1ebb9379b2f635755e773b79e88cb99852c70455/cpp/src/arrow/array/validate.cc#L456-L459).
`ValidateFull` now rejects a nonempty extension over null storage
claiming null count 0, as plain `null` does. Only `ValidateFull` checks
dictionary index bounds.
### Are these changes tested?
`TestMakeArrayOfNullNestedNull`'s added rows and
`TestValidateFullExtensionOverNullNullCountMismatch` fail on main and
pass with this change. Existing
`TestRunEndEncodedValidateConstructedArrays/extension` coverage still
passes.
On macOS arm64 with Go 1.26.10, `go test ./arrow/...` with arrow-testing
and parquet-testing checked out, `-race -tags assert,test` tests, vet,
lint and the Release Audit Tool passed.
### Are there any user-facing changes?
Yes. These valid extension arrays pass validation, while a wrong null
count on null storage is rejected. There is no API change.
Closes https://github.com/apache/arrow-go/issues/1483.
---
arrow/array/util_test.go | 34 ++++++++++++++++++++++++++++++++++
arrow/array/validate.go | 27 +++++++++++++++------------
2 files changed, 49 insertions(+), 12 deletions(-)
diff --git a/arrow/array/util_test.go b/arrow/array/util_test.go
index 3abd1a57..9c1d2d63 100644
--- a/arrow/array/util_test.go
+++ b/arrow/array/util_test.go
@@ -235,6 +235,10 @@ func TestMakeArrayOfNullNestedNull(t *testing.T) {
{arrow.SparseUnionOf([]arrow.Field{nullField},
[]arrow.UnionTypeCode{0}), false},
{arrow.DenseUnionOf([]arrow.Field{nullField},
[]arrow.UnionTypeCode{0}), false},
{extensions.NewOpaqueType(arrow.StructOf(nullField), "type",
"vendor"), true},
+ {extensions.NewOpaqueType(arrow.Null, "type", "vendor"), true},
+
{extensions.NewOpaqueType(arrow.SparseUnionOf([]arrow.Field{nullField},
[]arrow.UnionTypeCode{0}), "type", "vendor"), false},
+
{extensions.NewOpaqueType(arrow.DenseUnionOf([]arrow.Field{nullField},
[]arrow.UnionTypeCode{0}), "type", "vendor"), false},
+ {extensions.NewOpaqueType(&arrow.DictionaryType{IndexType:
arrow.PrimitiveTypes.Int8, ValueType: arrow.BinaryTypes.String}, "type",
"vendor"), true},
{arrow.StructOf(arrow.Field{Name: "d", Type:
&arrow.DictionaryType{IndexType: arrow.PrimitiveTypes.Int8, ValueType:
arrow.Null}, Nullable: true}), true},
}
for _, tt := range tests {
@@ -255,6 +259,36 @@ func TestMakeArrayOfNullNestedNull(t *testing.T) {
}
}
+func TestValidateFullExtensionOverNullNullCountMismatch(t *testing.T) {
+ data := array.NewData(extensions.NewOpaqueType(arrow.Null, "type",
"vendor"), 3, []*memory.Buffer{nil}, nil, 0, 0)
+ defer data.Release()
+ arr := array.MakeFromData(data)
+ defer arr.Release()
+
+ assert.NoError(t, array.Validate(arr))
+ err := array.ValidateFull(arr)
+ require.Error(t, err)
+ assert.Contains(t, err.Error(), "does not match actual number of nulls")
+}
+
+func TestValidateFullExtensionOverDictionaryChecksIndices(t *testing.T) {
+ dictType := &arrow.DictionaryType{IndexType: arrow.PrimitiveTypes.Int8,
ValueType: arrow.BinaryTypes.String}
+ dict, err := array.DictArrayFromJSON(memory.DefaultAllocator, dictType,
`[0, 1]`, `["only"]`)
+ require.NoError(t, err)
+ defer dict.Release()
+ storage := dict.Data()
+ data := array.NewData(extensions.NewOpaqueType(dictType, "type",
"vendor"), storage.Len(), storage.Buffers(), nil, storage.NullN(),
storage.Offset())
+ defer data.Release()
+ data.SetDictionary(storage.Dictionary())
+ arr := array.MakeFromData(data)
+ defer arr.Release()
+
+ assert.NoError(t, array.Validate(arr))
+ err = array.ValidateFull(arr)
+ require.Error(t, err)
+ assert.Contains(t, err.Error(), "dictionary indices")
+}
+
var typemap = map[arrow.DataType]reflect.Type{
arrow.PrimitiveTypes.Int8: reflect.TypeOf(int8(0)),
arrow.PrimitiveTypes.Uint8: reflect.TypeOf(uint8(0)),
diff --git a/arrow/array/validate.go b/arrow/array/validate.go
index f627b6ee..dd736491 100644
--- a/arrow/array/validate.go
+++ b/arrow/array/validate.go
@@ -90,7 +90,8 @@ func validateArray(arr arrow.Array, full bool, path string)
error {
}
}
- if full && data.DataType().Layout().HasDict {
+ // an extension array's indices are checked with its storage below
+ if full && data.DataType().ID() == arrow.DICTIONARY {
dictData := data.dictionary
if dictData != nil {
dt := data.DataType().(*arrow.DictionaryType)
@@ -143,7 +144,7 @@ func validateNullCount(data *Data) error {
}
var actualNulls int
- switch data.dtype.ID() {
+ switch storageType(data.dtype).ID() {
case arrow.NULL:
actualNulls = data.length
case arrow.SPARSE_UNION, arrow.DENSE_UNION, arrow.RUN_END_ENCODED:
@@ -160,6 +161,13 @@ func validateNullCount(data *Data) error {
return nil
}
+func storageType(dt arrow.DataType) arrow.DataType {
+ if ext, ok := dt.(arrow.ExtensionType); ok {
+ return ext.StorageType()
+ }
+ return dt
+}
+
func validateArrayData(data *Data) error {
if data == nil || data.dtype == nil {
return fmt.Errorf("arrow/array: array data has no data type")
@@ -181,21 +189,16 @@ func validateArrayData(data *Data) error {
// REE arrays have no physical buffers. Constructors and IPC may
include a
// nil placeholder, but builders and C Data imports omit it.
- if len(data.buffers) == 0 {
- dt := data.dtype
- if ext, ok := dt.(arrow.ExtensionType); ok {
- dt = ext.StorageType()
- }
- if dt.ID() == arrow.RUN_END_ENCODED {
- return nil
- }
+ id := storageType(data.dtype).ID()
+ if len(data.buffers) == 0 && id == arrow.RUN_END_ENCODED {
+ return nil
}
layout := data.dtype.Layout()
// Union arrays reserve the first buffer slot for a validity bitmap,
even
// though that slot must be nil and is not part of their type layout.
bufferOffset := 0
- if data.dtype.ID() == arrow.SPARSE_UNION || data.dtype.ID() ==
arrow.DENSE_UNION {
+ if id == arrow.SPARSE_UNION || id == arrow.DENSE_UNION {
bufferOffset = 1
}
bufferCount := len(data.buffers) - bufferOffset
@@ -278,7 +281,7 @@ func validateArrayStructure(data *Data) error {
}
if data.DataType().Layout().HasDict {
- dt, ok := data.DataType().(*arrow.DictionaryType)
+ dt, ok := storageType(data.DataType()).(*arrow.DictionaryType)
if !ok {
return fmt.Errorf("arrow/array: datatype %s declares
dictionary storage but is not a dictionary type", data.DataType())
}