Skip to content

Commit

Permalink
vam: Fix avg ConsumePartial
Browse files Browse the repository at this point in the history
Closes #5500
  • Loading branch information
mattnibs committed Nov 24, 2024
1 parent e737ee0 commit 64d93bc
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 3 deletions.
14 changes: 11 additions & 3 deletions runtime/vam/expr/agg/avg.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,16 @@ const (
)

func (a *avg) ConsumeAsPartial(partial vector.Any) {
if partial.Len() != 1 {
panic("avg: invalid partial")
}
idx := uint32(0)
if view, ok := partial.(*vector.View); ok {
idx = view.Index[0]
partial = view.Any
}
rec, ok := partial.(*vector.Record)
if !ok || rec.Len() != 1 {
if !ok {
panic("avg: invalid partial")
}
si, ok1 := rec.Typ.IndexOfField(sumName)
Expand All @@ -48,8 +56,8 @@ func (a *avg) ConsumeAsPartial(partial vector.Any) {
if sumVal.Type() != super.TypeFloat64 || countVal.Type() != super.TypeUint64 {
panic("avg: invalid partial")
}
sum, _ := vector.FloatValue(sumVal, 0)
count, _ := vector.UintValue(countVal, 0)
sum, _ := vector.FloatValue(sumVal, idx)
count, _ := vector.UintValue(countVal, idx)
a.sum += sum
a.count += count
}
Expand Down
1 change: 1 addition & 0 deletions runtime/vam/op/summarize/summarize.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func New(parent vector.Puller, zctx *super.Context, aggNames []field.Path, aggEx
}
return &Summarize{
parent: parent,
zctx: zctx,
aggs: aggs,
aggExprs: aggExprs,
keyExprs: keyExprs,
Expand Down

0 comments on commit 64d93bc

Please sign in to comment.