Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 8 additions & 0 deletions arrow/array/union.go
Original file line number Diff line number Diff line change
Expand Up @@ -1201,6 +1201,10 @@ func (b *DenseUnionBuilder) AppendNull() {
// for a DenseUnion this is more efficient than calling AppendNull multiple
// times in a loop
func (b *DenseUnionBuilder) AppendNulls(n int) {
if n <= 0 {
return
}

// only append 1 null to the child builder, use the same offset twice
firstChildCode := b.codes[0]
childBuilder := b.typeIDtoBuilder[firstChildCode]
Expand Down Expand Up @@ -1228,6 +1232,10 @@ func (b *DenseUnionBuilder) AppendEmptyValue() {
// at that value using the offsets n times. That makes this more efficient
// than calling AppendEmptyValue multiple times.
func (b *DenseUnionBuilder) AppendEmptyValues(n int) {
if n <= 0 {
return
}

// only append 1 null to the child builder, use the same offset twice
firstChildCode := b.codes[0]
childBuilder := b.typeIDtoBuilder[firstChildCode]
Expand Down
24 changes: 24 additions & 0 deletions arrow/array/union_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1148,6 +1148,30 @@ func TestUnions(t *testing.T) {
suite.Run(t, new(UnionBuilderSuite))
}

func TestDenseUnionBuilderZeroBulkAppendDoesNotMutateChildren(t *testing.T) {
mem := memory.NewCheckedAllocator(memory.NewGoAllocator())
defer mem.AssertSize(t, 0)

typ := arrow.DenseUnionOf(
[]arrow.Field{{Name: "value", Type: arrow.PrimitiveTypes.Int32}},
[]arrow.UnionTypeCode{0},
)
builder := array.NewDenseUnionBuilder(mem, typ)
defer builder.Release()

builder.AppendNulls(0)
builder.AppendEmptyValues(0)
assert.Zero(t, builder.Len())
assert.Zero(t, builder.Child(0).Len())

builder.Append(0)
builder.Child(0).(*array.Int32Builder).Append(42)
result := builder.NewDenseUnionArray()
defer result.Release()
assert.EqualValues(t, 0, result.ValueOffset(0))
assert.EqualValues(t, 42, result.Field(0).(*array.Int32).Value(0))
}

func TestNestedUnionStructDict(t *testing.T) {
// ARROW-18274
dt1 := arrow.SparseUnionOf([]arrow.Field{
Expand Down
Loading