Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

vector.View: rebuild nulls #5312

Merged
merged 2 commits into from
Oct 1, 2024
Merged
Changes from 1 commit
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
22 changes: 21 additions & 1 deletion vector/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ var _ Any = (*View)(nil)

func NewView(index []uint32, val Any) Any {
switch val := val.(type) {
case *Const:
return NewConst(val.val, uint32(len(index)), nullsView(val.Nulls, index))
case *Dict:
index2 := make([]byte, len(index))
nulls := NewBoolEmpty(uint32(len(index)), nil)
Expand All @@ -23,9 +25,11 @@ func NewView(index []uint32, val Any) Any {
index2[k] = val.Index[idx]
}
return NewDict(val.Any, index2, nil, nulls)
case *Error:
return NewError(val.Typ, NewView(index, val.Vals), nullsView(val.Nulls, index))
case *Union:
tags, values := viewForUnionOrDynamic(index, val.Tags, val.TagMap.Forward, val.Values)
return NewUnion(val.Typ, tags, values, nil)
return NewUnion(val.Typ, tags, values, nullsView(val.Nulls, index))
case *Dynamic:
return NewDynamic(viewForUnionOrDynamic(index, val.Tags, val.TagMap.Forward, val.Values))
case *View:
Expand All @@ -38,6 +42,22 @@ func NewView(index []uint32, val Any) Any {
return &View{val, index}
}

func nullsView(nulls *Bool, index []uint32) *Bool {
if nulls == nil {
return nil
}
out := NewBoolEmpty(uint32(len(index)), nil)
for k, slot := range index {
if nulls.Value(slot) {
out.Set(uint32(k))
}
}
if out.Len() > 0 {
return out
}
return nil
mattnibs marked this conversation as resolved.
Show resolved Hide resolved
}

func viewForUnionOrDynamic(index, tags, forward []uint32, values []Any) ([]uint32, []Any) {
indexes := make([][]uint32, len(values))
resultTags := make([]uint32, len(index))
Expand Down