Skip to content

Commit 1fec2db

Browse files
authored
Fix nulls in aggregations with distinct (#6420)
Closes #6395
1 parent a79d960 commit 1fec2db

File tree

3 files changed

+15
-4
lines changed

3 files changed

+15
-4
lines changed

runtime/sam/expr/agg/distinct.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66

77
"github.com/brimdata/super"
8+
"github.com/brimdata/super/scode"
89
)
910

1011
type distinct struct {
@@ -21,7 +22,7 @@ func newDistinct(f Function) Function {
2122

2223
func (d *distinct) Consume(val super.Value) {
2324
d.buf = binary.AppendVarint(d.buf[:0], int64(val.Type().ID()))
24-
d.buf = append(d.buf, val.Bytes()...)
25+
d.buf = scode.Append(d.buf, val.Bytes())
2526
if _, ok := d.seen[string(d.buf)]; ok {
2627
return
2728
}
@@ -60,7 +61,7 @@ func (d *distinct) Result(sctx *super.Context) super.Value {
6061
if err != nil {
6162
panic(err)
6263
}
63-
d.fun.Consume(super.NewValue(typ, bytes))
64+
d.fun.Consume(super.NewValue(typ, scode.Bytes(bytes).Body()))
6465
delete(d.seen, key)
6566
}
6667
return d.fun.Result(sctx)

runtime/vam/expr/agg/distinct.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ func (d *distinct) Consume(vec vector.Any) {
2828
b.Truncate()
2929
vec.Serialize(&b, i)
3030
d.buf = binary.AppendVarint(d.buf[:0], int64(id))
31-
d.buf = append(d.buf, b.Bytes().Body()...)
31+
d.buf = append(d.buf, b.Bytes()...)
3232
if _, ok := d.seen[string(d.buf)]; ok {
3333
continue
3434
}
@@ -71,7 +71,7 @@ func (d *distinct) Result(sctx *super.Context) super.Value {
7171
if err != nil {
7272
panic(err)
7373
}
74-
b.Write(super.NewValue(typ, bytes))
74+
b.Write(super.NewValue(typ, scode.Bytes(bytes).Body()))
7575
count++
7676
if count == 1024 {
7777
d.fun.Consume(b.Build())
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
spq: |
2+
avg(distinct this), count(distinct this), collect(distinct this), sum(distinct this)
3+
4+
vector: true
5+
6+
input: |
7+
null::float64
8+
9+
output: |
10+
{avg:null::float64,count:0::uint64,collect:null,sum:null::float64}

0 commit comments

Comments
 (0)