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 fc5d5ce5 fix(arrow): give IPC and C Data null arrays their layout
buffer (#1550)
fc5d5ce5 is described below
commit fc5d5ce5a99b8583448b2cb70d0e9357dd10a420
Author: Matt Topol <[email protected]>
AuthorDate: Fri Nov 13 13:45:11 2026 -0500
fix(arrow): give IPC and C Data null arrays their layout buffer (#1550)
### Rationale for this change
`NullType.Layout()` declares one always-null buffer, and `array.NewNull`
/ `NullBuilder` build null data with `[]*memory.Buffer{nil}`. The IPC
reader (`loadNull`) and the C Data importer built null data with **no**
buffers, so `array.ValidateFull` rejects every decoded or imported null
array (`expected at least 1 buffers for null, got 0`), including null
children of structs and lists.
### What changes are included in this PR?
- `arrow/ipc`: `loadNull` builds null data with a single nil buffer.
- `arrow/cdata`: the null-type import does the same.
Export is unchanged: null types have no validity bitmap, so
`exportArray` still drops the slot and `n_buffers` stays 0.
### Are these changes tested?
Yes. New `TestNullArrayRoundTripValidateFull` (top-level null,
`struct<null>`, `list<null>` through IPC) and `TestPrimitiveArrs` now
runs `ValidateFull` on every imported array. Both fail without the fix.
### Are there any user-facing changes?
Null arrays read from IPC or imported via C Data now pass
`ValidateFull`.
---
arrow/cdata/cdata.go | 3 ++-
arrow/cdata/cdata_test.go | 3 ++-
arrow/ipc/file_reader.go | 3 ++-
arrow/ipc/ipc_test.go | 33 +++++++++++++++++++++++++++++++++
4 files changed, 39 insertions(+), 3 deletions(-)
diff --git a/arrow/cdata/cdata.go b/arrow/cdata/cdata.go
index de17b0ed..299f359e 100644
--- a/arrow/cdata/cdata.go
+++ b/arrow/cdata/cdata.go
@@ -719,7 +719,8 @@ func (imp *cimporter) doImport() error {
return err
}
- imp.data = array.NewData(dt, int(imp.arr.length), nil, nil,
int(imp.arr.null_count), int(imp.arr.offset))
+ // NullType's layout has one always-null buffer, which C Data
does not export.
+ imp.data = array.NewData(dt, int(imp.arr.length),
[]*memory.Buffer{nil}, nil, int(imp.arr.null_count), int(imp.arr.offset))
case arrow.FixedWidthDataType:
return imp.importFixedSizePrimitive()
case *arrow.StringType:
diff --git a/arrow/cdata/cdata_test.go b/arrow/cdata/cdata_test.go
index b9ee87c2..f4464386 100644
--- a/arrow/cdata/cdata_test.go
+++ b/arrow/cdata/cdata_test.go
@@ -583,7 +583,8 @@ func TestPrimitiveArrs(t *testing.T) {
defer freeTestMallocatorArr(carr, mem)
imported, err := ImportCArrayWithType(carr,
arr.DataType())
- assert.NoError(t, err)
+ require.NoError(t, err)
+ assert.NoError(t, array.ValidateFull(imported))
assert.True(t, array.Equal(arr, imported))
assert.True(t, isReleased(carr))
diff --git a/arrow/ipc/file_reader.go b/arrow/ipc/file_reader.go
index 1addd8dd..1a7f0ed9 100644
--- a/arrow/ipc/file_reader.go
+++ b/arrow/ipc/file_reader.go
@@ -761,7 +761,8 @@ func (ctx *arrayLoaderContext) loadChild(dt arrow.DataType)
arrow.ArrayData {
func (ctx *arrayLoaderContext) loadNull() arrow.ArrayData {
field := ctx.field()
- return array.NewData(arrow.Null, int(field.Length()), nil, nil,
int(field.NullCount()), 0)
+ // NullType's layout has one always-null buffer, which IPC does not
encode.
+ return array.NewData(arrow.Null, int(field.Length()),
[]*memory.Buffer{nil}, nil, int(field.NullCount()), 0)
}
func (ctx *arrayLoaderContext) loadPrimitive(dt arrow.DataType)
arrow.ArrayData {
diff --git a/arrow/ipc/ipc_test.go b/arrow/ipc/ipc_test.go
index 0f4b9213..6db19b76 100644
--- a/arrow/ipc/ipc_test.go
+++ b/arrow/ipc/ipc_test.go
@@ -783,6 +783,39 @@ func TestZeroSizeFixedSizeListRoundTrip(t *testing.T) {
}
}
+func TestNullArrayRoundTripValidateFull(t *testing.T) {
+ for _, dt := range []arrow.DataType{
+ arrow.Null,
+ arrow.StructOf(arrow.Field{Name: "n", Type: arrow.Null,
Nullable: true}),
+ arrow.ListOf(arrow.Null),
+ } {
+ t.Run(dt.String(), func(t *testing.T) {
+ mem :=
memory.NewCheckedAllocator(memory.DefaultAllocator)
+ defer mem.AssertSize(t, 0)
+ arr, _, err := array.FromJSON(mem, dt,
strings.NewReader(`[null, null, null]`))
+ require.NoError(t, err)
+ defer arr.Release()
+ schema := arrow.NewSchema([]arrow.Field{{Name: "col",
Type: dt, Nullable: true}}, nil)
+ rec := array.NewRecordBatch(schema, []arrow.Array{arr},
int64(arr.Len()))
+ defer rec.Release()
+
+ var buf bytes.Buffer
+ writer := ipc.NewWriter(&buf, ipc.WithSchema(schema),
ipc.WithAllocator(mem))
+ defer writer.Close()
+ require.NoError(t, writer.Write(rec))
+ require.NoError(t, writer.Close())
+
+ reader, err := ipc.NewReader(&buf,
ipc.WithAllocator(mem))
+ require.NoError(t, err)
+ defer reader.Release()
+ require.True(t, reader.Next())
+ got := reader.RecordBatch()
+ require.NoError(t, array.ValidateFull(got.Column(0)))
+ assert.True(t, array.RecordEqual(rec, got))
+ })
+ }
+}
+
func TestRecordBatchCustomMetadataRoundtrip(t *testing.T) {
mem := memory.NewGoAllocator()
schema := arrow.NewSchema(