From a6f8ac2ab8457520071b3a2a247f8688a9042272 Mon Sep 17 00:00:00 2001 From: Matthew Nibecker Date: Tue, 1 Oct 2024 18:13:38 -0400 Subject: [PATCH] vector.View: rebuild nulls (#5312) The commit changes the behavior when wrapping Const, Errors and Unions. Consts and Errors are now rebuilt rather than getting wrapped in a View. For all these values if there is a non-nil nulls value the Bool vector is rebuilt. --- vector/view.go | 22 +++++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/vector/view.go b/vector/view.go index b42936ae8b..f147245d30 100644 --- a/vector/view.go +++ b/vector/view.go @@ -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) @@ -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: @@ -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 + } + var out *Bool + for k, slot := range index { + if nulls.Value(slot) { + if out == nil { + out = NewBoolEmpty(uint32(len(index)), nil) + } + out.Set(uint32(k)) + } + } + return out +} + func viewForUnionOrDynamic(index, tags, forward []uint32, values []Any) ([]uint32, []Any) { indexes := make([][]uint32, len(values)) resultTags := make([]uint32, len(index))