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 a211d2cc fix(arrow/array): print struct arrays with run-end encoded
children (#1532)
a211d2cc is described below
commit a211d2cc59e31fda45b18e0c49b4e69d67dbcb2b
Author: Matt Topol <[email protected]>
AuthorDate: Mon Nov 16 11:25:38 2026 -0500
fix(arrow/array): print struct arrays with run-end encoded children (#1532)
### Rationale for this change
`Struct.String` panics with `index out of range [0] with length 0` when
a struct has a run-end encoded child and the struct's validity bitmap
differs from the child's, for example after appending a null struct. The
array is valid; only printing fails.
### What changes are included in this PR?
`String` combines each child's validity bitmap with the parent's by
replacing buffer 0 of the child's data. Run-end encoded arrays have no
buffers, so there is no bitmap to combine. Such children are now printed
as they are, the same way union children already are. This also covers
extension types with run-end encoded storage.
### Are these changes tested?
Yes.
### Are there any user-facing changes?
Printing a struct array with a run-end encoded child no longer panics.
Closes #1531.
---
arrow/array/struct.go | 4 +++-
arrow/array/struct_test.go | 22 ++++++++++++++++++++++
2 files changed, 25 insertions(+), 1 deletion(-)
diff --git a/arrow/array/struct.go b/arrow/array/struct.go
index a9d80835..15202b55 100644
--- a/arrow/array/struct.go
+++ b/arrow/array/struct.go
@@ -182,7 +182,9 @@ func (a *Struct) String() string {
if i > 0 {
o.WriteString(" ")
}
- if arrow.IsUnion(v.DataType().ID()) {
+ if arrow.IsUnion(v.DataType().ID()) || len(v.Data().Buffers())
== 0 {
+ // Unions and run-end encoded arrays have no validity
bitmap to
+ // combine with the parent's, so print them as they are.
fmt.Fprintf(o, "%v", v)
continue
} else if a.Offset() != v.Data().Offset() ||
!bytes.Equal(structBitmap, v.NullBitmapBytes()) {
diff --git a/arrow/array/struct_test.go b/arrow/array/struct_test.go
index 74fda503..d8a097b0 100644
--- a/arrow/array/struct_test.go
+++ b/arrow/array/struct_test.go
@@ -516,6 +516,28 @@ func
TestStructArrayStringerMasksRequiredChildWithoutNullBitmap(t *testing.T) {
})
}
+// A run-end encoded child has no buffers, so there is no validity bitmap to
+// combine with the parent's. String prints it as it is, as for unions.
+func TestStructArrayStringerRunEndEncodedChild(t *testing.T) {
+ pool := memory.NewCheckedAllocator(memory.NewGoAllocator())
+ defer pool.AssertSize(t, 0)
+
+ dt := arrow.StructOf(arrow.Field{Name: "r", Nullable: true,
+ Type: arrow.RunEndEncodedOf(arrow.PrimitiveTypes.Int32,
arrow.BinaryTypes.String)})
+ bldr := array.NewStructBuilder(pool, dt)
+ defer bldr.Release()
+ bldr.Append(true)
+
bldr.FieldBuilder(0).(*array.RunEndEncodedBuilder).AppendValueFromString("a")
+ bldr.AppendNull()
+ arr := bldr.NewArray()
+ defer arr.Release()
+ require.NoError(t, array.ValidateFull(arr))
+
+ assert.NotPanics(t, func() {
+ assert.Equal(t, `{[{1 -> a},{2 -> <nil>}]}`, arr.String())
+ })
+}
+
func TestNewStructArrayWithNullsValidatesOffset(t *testing.T) {
builder := array.NewInt32Builder(memory.DefaultAllocator)
defer builder.Release()