From 42187f8e1ae0a3066af03b265dfabec089782776 Mon Sep 17 00:00:00 2001 From: Matthew Nibecker Date: Thu, 12 Dec 2024 09:52:09 -0800 Subject: [PATCH] vam: Fix avg count for nulls (#5528) Fix a bug in the vector runtime for the avg aggregation where null values were improperly being counted Closes #5516 --- runtime/vam/expr/agg/avg.go | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/runtime/vam/expr/agg/avg.go b/runtime/vam/expr/agg/avg.go index 173c53d293..b9e95b6e6b 100644 --- a/runtime/vam/expr/agg/avg.go +++ b/runtime/vam/expr/agg/avg.go @@ -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 {