Skip to content

Commit

Permalink
Fix vector.Builder empty record handling (#5579)
Browse files Browse the repository at this point in the history
recordBuilder.Build panics with empty records because
len(recordBuilder.values)==0.  Fix by tracking vector length explicitly.
  • Loading branch information
nwt authored Jan 17, 2025
1 parent 66b20d0 commit 3eea13c
Showing 1 changed file with 3 additions and 1 deletion.
4 changes: 3 additions & 1 deletion vector/builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,7 @@ func (n *nullsBuilder) Build() Any {
type recordBuilder struct {
typ *super.TypeRecord
values []Builder
len uint32
}

func newRecordBuilder(typ *super.TypeRecord) Builder {
Expand All @@ -151,6 +152,7 @@ func newRecordBuilder(typ *super.TypeRecord) Builder {
}

func (r *recordBuilder) Write(bytes zcode.Bytes) {
r.len++
if bytes == nil {
for _, v := range r.values {
v.Write(nil)
Expand All @@ -168,7 +170,7 @@ func (r *recordBuilder) Build() Any {
for _, v := range r.values {
vecs = append(vecs, v.Build())
}
return NewRecord(r.typ, vecs, vecs[0].Len(), nil)
return NewRecord(r.typ, vecs, r.len, nil)
}

type errorBuilder struct {
Expand Down

0 comments on commit 3eea13c

Please sign in to comment.