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 4ab8bc04 fix(arrow/array): keep the storage dictionary in
NewExtensionArrayWithStorage (#1540)
4ab8bc04 is described below
commit 4ab8bc049dbbe1f34bb2a32ebdb75a11395be94b
Author: Harrison Crosse <[email protected]>
AuthorDate: Thu Nov 12 12:00:39 2026 -0500
fix(arrow/array): keep the storage dictionary in
NewExtensionArrayWithStorage (#1540)
### Rationale for this change
Wrapping dictionary storage panics or silently loses its dictionary.
### What changes are included in this PR?
I retain the storage dictionary with `SetDictionary`, as
`ExtensionArrayBase.setData` already does.
### Are these changes tested?
`TestNewExtensionArrayWithStorageKeepsDictionary` fails on main and
passes with this change. It checks independent lifetimes by validating
the extension, releasing it, then validating the original storage. A
checked allocator confirms that all memory is released.
With Go 1.26.10, vet, `go test -race -tags assert,test ./arrow/...` with
pinned `arrow-testing` and `parquet-testing` data, `golangci-lint`
2.13.2 and the Release Audit Tool passed.
### Are there any user-facing changes?
Yes. `NewExtensionArrayWithStorage` preserves the storage dictionary.
There is no API change.
Closes https://github.com/apache/arrow-go/issues/1535.
---
arrow/array/extension.go | 1 +
arrow/array/extension_test.go | 17 +++++++++++++++++
2 files changed, 18 insertions(+)
diff --git a/arrow/array/extension.go b/arrow/array/extension.go
index c82db8e0..a910725f 100644
--- a/arrow/array/extension.go
+++ b/arrow/array/extension.go
@@ -78,6 +78,7 @@ func NewExtensionArrayWithStorage(dt arrow.ExtensionType,
storage arrow.Array) a
// create a new data instance with the ExtensionType as the datatype
but referencing the
// same underlying buffers to share them with the storage array.
data := NewData(dt, storageData.length, storageData.buffers,
storageData.childData, storageData.nulls, storageData.offset)
+ data.SetDictionary(storageData.dictionary)
defer data.Release()
return NewExtensionData(data)
}
diff --git a/arrow/array/extension_test.go b/arrow/array/extension_test.go
index d3875eda..902a8bfe 100644
--- a/arrow/array/extension_test.go
+++ b/arrow/array/extension_test.go
@@ -21,6 +21,7 @@ import (
"github.com/apache/arrow-go/v18/arrow"
"github.com/apache/arrow-go/v18/arrow/array"
+ "github.com/apache/arrow-go/v18/arrow/extensions"
"github.com/apache/arrow-go/v18/arrow/memory"
"github.com/apache/arrow-go/v18/internal/types"
"github.com/stretchr/testify/require"
@@ -100,6 +101,22 @@ func
TestNewExtensionArrayWithStorageReleasesAllReferences(t *testing.T) {
mem.AssertSize(t, 0)
}
+func TestNewExtensionArrayWithStorageKeepsDictionary(t *testing.T) {
+ mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
+ defer mem.AssertSize(t, 0)
+
+ dictType := &arrow.DictionaryType{IndexType: arrow.PrimitiveTypes.Int8,
ValueType: arrow.BinaryTypes.String}
+ storage, err := array.DictArrayFromJSON(mem, dictType, `[0, null, 1,
0]`, `["a", "b"]`)
+ require.NoError(t, err)
+ defer storage.Release()
+
+ ext :=
array.NewExtensionArrayWithStorage(extensions.NewOpaqueType(dictType, "type",
"vendor"), storage)
+ require.NoError(t, array.ValidateFull(ext))
+ ext.Release()
+
+ require.NoError(t, array.ValidateFull(storage))
+}
+
func TestExtensionTypes(t *testing.T) {
suite.Run(t, new(ExtensionTypeTestSuite))
}