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 5b744803 fix(arrow/ipc): open mapped files with dictionary fields
(#1365)
5b744803 is described below
commit 5b7448037c16232df9e58c5e501a65d0c13859c1
Author: hp <[email protected]>
AuthorDate: Tue Oct 13 10:09:53 2026 -0400
fix(arrow/ipc): open mapped files with dictionary fields (#1365)
### Rationale for this change
`NewMappedFileReader` panics on dictionary fields because its memo is
uninitialized. Fixes #1364.
### What changes are included in this PR?
Initialize the mapped reader's memo and add a dictionary readback test.
### Are these changes tested?
`go test ./arrow/ipc -count=1`
### Are there any user-facing changes?
Yes. Mapped file readers can now open and read files with dictionary
fields.
---
arrow/ipc/file_reader.go | 3 ++-
arrow/ipc/reader_test.go | 36 ++++++++++++++++++++++++++++++++++++
2 files changed, 38 insertions(+), 1 deletion(-)
diff --git a/arrow/ipc/file_reader.go b/arrow/ipc/file_reader.go
index afcc20b3..1addd8dd 100644
--- a/arrow/ipc/file_reader.go
+++ b/arrow/ipc/file_reader.go
@@ -237,7 +237,8 @@ func NewMappedFileReader(data []byte, opts ...Option)
(*FileReader, error) {
maxMetadataSize: cfg.maxMetadataSize,
maxBodySize: cfg.maxBodySize,
},
- mem: cfg.alloc,
+ memo: dictutils.NewMemo(),
+ mem: cfg.alloc,
}
)
diff --git a/arrow/ipc/reader_test.go b/arrow/ipc/reader_test.go
index 0f3dcfe3..5f1017ef 100644
--- a/arrow/ipc/reader_test.go
+++ b/arrow/ipc/reader_test.go
@@ -170,6 +170,42 @@ func TestMappedReader(t *testing.T) {
assert.Equal(t, (*byte)(loc),
unsafe.SliceData(rec.Column(0).Data().Buffers()[1].Bytes()))
}
+func TestMappedReaderDictionary(t *testing.T) {
+ pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
+ defer pool.AssertSize(t, 0)
+ schema := arrow.NewSchema([]arrow.Field{{
+ Name: "value",
+ Type: &arrow.DictionaryType{
+ IndexType: arrow.PrimitiveTypes.Int32,
+ ValueType: arrow.BinaryTypes.String,
+ },
+ }}, nil)
+
+ b := array.NewRecordBuilder(pool, schema)
+ defer b.Release()
+ col := b.Field(0).(*array.BinaryDictionaryBuilder)
+ for _, value := range []string{"alpha", "beta", "alpha"} {
+ require.NoError(t, col.AppendString(value))
+ }
+ record := b.NewRecordBatch()
+ defer record.Release()
+
+ var buf bytes.Buffer
+ writer, err := NewFileWriter(&buf, WithAllocator(pool),
WithSchema(schema))
+ require.NoError(t, err)
+ require.NoError(t, writer.Write(record))
+ require.NoError(t, writer.Close())
+
+ rdr, err := NewMappedFileReader(buf.Bytes(), WithAllocator(pool))
+ require.NoError(t, err)
+ defer rdr.Close()
+
+ got, err := rdr.RecordBatchAt(0)
+ require.NoError(t, err)
+ defer got.Release()
+ require.True(t, array.RecordEqual(record, got))
+}
+
func BenchmarkIPC(b *testing.B) {
alloc := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer alloc.AssertSize(b, 0)