Skip to content

Commit

Permalink
vector: Fix Apply (#5263)
Browse files Browse the repository at this point in the history
The commit a bug where Apply would not properly combine arguments with
more than one Variant/Union.
  • Loading branch information
mattnibs authored Sep 11, 2024
1 parent 7d8c575 commit ab07f4d
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
8 changes: 4 additions & 4 deletions vector/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ func Apply(ripUnions bool, eval func(...Any) Any, vecs ...Any) Any {
return eval(vecs...)
}
var results []Any
for _, ripped := range rip(vecs, variant.TagMap.Reverse) {
for _, ripped := range rip(vecs, variant) {
results = append(results, Apply(ripUnions, eval, ripped...))
}
// Stitch results together by creating a Variant.
Expand All @@ -33,12 +33,12 @@ func findVariant(vecs []Any) (*Variant, bool) {
return nil, false
}

func rip(vecs []Any, reverse [][]uint32) [][]Any {
func rip(vecs []Any, variant *Variant) [][]Any {
var ripped [][]Any
for j, rev := range reverse {
for j, rev := range variant.TagMap.Reverse {
var newVecs []Any
for _, vec := range vecs {
if variant, ok := vec.(*Variant); ok {
if vec == variant {
newVecs = append(newVecs, variant.Values[j])
} else {
newVecs = append(newVecs, NewView(rev, vec))
Expand Down
9 changes: 2 additions & 7 deletions vector/string.go
Original file line number Diff line number Diff line change
Expand Up @@ -63,14 +63,9 @@ func StringValue(val Any, slot uint32) (string, bool) {
if val.Nulls.Value(slot) {
return "", true
}
slot = uint32(val.Index[slot])
return val.Any.(*String).Value(slot), false
return StringValue(val.Any, uint32(val.Index[slot]))
case *View:
slot = val.Index[slot]
if val.Any.(*String).Nulls.Value(slot) {
return "", true
}
return val.Any.(*String).Value(slot), false
return StringValue(val.Any, val.Index[slot])
}
panic(val)
}
12 changes: 7 additions & 5 deletions vector/view.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ var _ Any = (*View)(nil)

func NewView(index []uint32, val Any) Any {
switch val := val.(type) {
case *Const:
return NewConst(val.arena, val.Value(), uint32(len(index)), nil)
case *Dict:
index2 := make([]uint32, len(index))
index2 := make([]byte, len(index))
nulls := NewBoolEmpty(uint32(len(index)), nil)
for k, idx := range index {
index2[k] = uint32(val.Index[idx])
if val.Nulls.Value(idx) {
nulls.Set(uint32(k))
}
index2[k] = val.Index[idx]
}
return &View{val.Any, index2}
return NewDict(val.Any, index2, nil, nulls)
case *Union:
tags, values := viewForUnionOrVariant(index, val.Tags, val.TagMap.Forward, val.Values)
return NewUnion(val.Typ, tags, values, nil)
Expand Down

0 comments on commit ab07f4d

Please sign in to comment.