Skip to content

Commit d5db318

Browse files
committed
vam: Fix summarize where
Fix issue with incorrect counts when using where clauses on a aggregation function in vector runtime. If a value fails the where clause make the value as null so it is skipped by the aggregation function. Closes #5468
1 parent e7d0376 commit d5db318

File tree

3 files changed

+34
-22
lines changed

3 files changed

+34
-22
lines changed

runtime/vam/expr/agg/count.go

+8-13
Original file line numberDiff line numberDiff line change
@@ -10,25 +10,20 @@ type count struct {
1010
}
1111

1212
func (a *count) Consume(vec vector.Any) {
13-
if c, ok := vec.(*vector.Const); ok {
14-
val := c.Value()
15-
if !val.IsNull() && !val.IsError() {
16-
a.count += uint64(vec.Len())
17-
}
13+
if c, ok := vec.(*vector.Const); ok && c.Value().IsNull() {
1814
return
1915
}
2016
if _, ok := vector.Under(vec).Type().(*super.TypeError); ok {
2117
return
2218
}
23-
nulls := vector.NullsOf(vec)
24-
if nulls == nil {
25-
a.count += uint64(vec.Len())
26-
return
27-
}
28-
for i := range vec.Len() {
29-
if !nulls.Value(i) {
30-
a.count++
19+
if nulls := vector.NullsOf(vec); nulls != nil {
20+
for i := range vec.Len() {
21+
if !nulls.Value(i) {
22+
a.count++
23+
}
3124
}
25+
} else {
26+
a.count += uint64(vec.Len())
3227
}
3328
}
3429

runtime/vam/expr/aggregator.go

+9-9
Original file line numberDiff line numberDiff line change
@@ -41,15 +41,15 @@ func (a *Aggregator) Eval(this vector.Any) vector.Any {
4141

4242
func (a *Aggregator) apply(args ...vector.Any) vector.Any {
4343
vec, where := args[0], args[1]
44-
var tags []uint32
45-
// If type is not bool then we want to filter everything.
46-
if where.Type().ID() == super.IDBool {
47-
for slot := uint32(0); slot < where.Len(); slot++ {
48-
// XXX Feels like we should have a optimzed version of this.
49-
if vector.BoolValue(where, slot) {
50-
tags = append(tags, slot)
51-
}
44+
bools, _ := BoolMask(where)
45+
bools.Flip(0, uint64(vec.Len()))
46+
if !bools.IsEmpty() {
47+
nulls := vector.NewBoolEmpty(vec.Len(), nil)
48+
bools.WriteDenseTo(nulls.Bits)
49+
if origNulls := vector.NullsOf(vec); origNulls != nil {
50+
nulls = vector.Or(nulls, origNulls)
5251
}
52+
vector.SetNulls(vec, nulls)
5353
}
54-
return vector.NewView(vec, tags)
54+
return vec
5555
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
zed: |
2+
summarize
3+
num_requests := count()
4+
where log_time >= 2012-10-01T00:00:00Z
5+
by client_ip
6+
| sort client_ip
7+
8+
vector: true
9+
10+
input: |
11+
{log_time:2012-01-01T00:00:44Z,client_ip:249.92.17.134}
12+
{log_time:2012-10-01T00:24:30Z,client_ip:249.92.17.134}
13+
{log_time:2012-05-12T10:23:22Z,client_ip:251.58.48.137}
14+
15+
output: |
16+
{client_ip:249.92.17.134,num_requests:1(uint64)}
17+
{client_ip:251.58.48.137,num_requests:0(uint64)}

0 commit comments

Comments
 (0)