Skip to content

Commit

Permalink
vam: Fix avg count for nulls (#5528)
Browse files Browse the repository at this point in the history
Fix a bug in the vector runtime for the avg aggregation where null
values were improperly being counted

Closes #5516
  • Loading branch information
mattnibs authored Dec 12, 2024
1 parent 6e7d041 commit 42187f8
Showing 1 changed file with 7 additions and 4 deletions.
11 changes: 7 additions & 4 deletions runtime/vam/expr/agg/avg.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,14 @@ type avg struct {
var _ Func = (*avg)(nil)

func (a *avg) Consume(vec vector.Any) {
if isNull(vec) {
return
var ncount uint32
if nulls := vector.NullsOf(vec); nulls != nil {
ncount = nulls.TrueCount()
}
if ncount != vec.Len() {
a.count += uint64(vec.Len() - ncount)
a.sum = sum(a.sum, vec)
}
a.count += uint64(vec.Len())
a.sum = sum(a.sum, vec)
}

func (a *avg) Result(*super.Context) super.Value {
Expand Down

0 comments on commit 42187f8

Please sign in to comment.