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

Avoid creating empty vectors in vector.Apply #5540

Merged
merged 1 commit into from
Dec 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
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
18 changes: 12 additions & 6 deletions vector/apply.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,11 @@ func Apply(ripUnions bool, eval func(...Any) Any, vecs ...Any) Any {
}
var results []Any
for _, ripped := range rip(vecs, d) {
results = append(results, Apply(ripUnions, eval, ripped...))
var result Any
if len(ripped) > 0 {
result = Apply(ripUnions, eval, ripped...)
}
results = append(results, result)
}
return stitch(d.Tags, results)
}
Expand All @@ -36,11 +40,13 @@ func rip(vecs []Any, d *Dynamic) [][]Any {
var ripped [][]Any
for j, rev := range d.TagMap.Reverse {
var newVecs []Any
for _, vec := range vecs {
if vec == d {
newVecs = append(newVecs, d.Values[j])
} else {
newVecs = append(newVecs, NewView(vec, rev))
if len(rev) > 0 {
for _, vec := range vecs {
if vec == d {
newVecs = append(newVecs, d.Values[j])
} else {
newVecs = append(newVecs, NewView(vec, rev))
}
}
}
ripped = append(ripped, newVecs)
Expand Down
6 changes: 5 additions & 1 deletion vector/tagmap.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,11 @@ type TagMap struct {
func NewTagMap(tags []uint32, vals []Any) *TagMap {
lens := make([]uint32, 0, len(vals))
for _, v := range vals {
lens = append(lens, uint32(v.Len()))
var length uint32
if v != nil {
length = v.Len()
}
lens = append(lens, length)
}
return NewTagMapFromLens(tags, lens)
}
Expand Down