Skip to content

Commit

Permalink
vector: Fix union nulls (#5555)
Browse files Browse the repository at this point in the history
This commit fixes nulls in vector Unions by added a const null vector of
union type into the Union dynamic.
  • Loading branch information
mattnibs authored Jan 6, 2025
1 parent 06f8f66 commit dd555cf
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 1 deletion.
22 changes: 21 additions & 1 deletion runtime/vcache/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,5 +124,25 @@ func projectUnion(zctx *super.Context, paths Path, s *union) vector.Any {
vals = append(vals, val)
types = append(types, val.Type())
}
return vector.NewUnion(zctx.LookupTypeUnion(types), s.tags, vals, s.nulls.flat)
utyp := zctx.LookupTypeUnion(types)
tags := s.tags
nulls := s.nulls.flat
// If there are nulls add a null vector and rebuild tags.
if nulls != nil {
var newtags []uint32
n := uint32(len(vals))
var nullcount uint32
for i := range nulls.Len() {
if nulls.Value(i) {
newtags = append(newtags, n)
nullcount++
} else {
newtags = append(newtags, tags[0])
tags = tags[1:]
}
}
tags = newtags
vals = append(vals, vector.NewConst(super.NewValue(utyp, nil), nullcount, nil))
}
return vector.NewUnion(utyp, tags, vals, nulls)
}
4 changes: 4 additions & 0 deletions vector/union.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,10 @@ func (u *Union) Type() super.Type {
}

func (u *Union) Serialize(b *zcode.Builder, slot uint32) {
if u.Nulls.Value(slot) {
b.Append(nil)
return
}
b.BeginContainer()
tag := u.Typ.TagOf(u.TypeOf(slot))
b.Append(super.EncodeInt(int64(tag)))
Expand Down

0 comments on commit dd555cf

Please sign in to comment.