Skip to content

Commit 1216a86

Browse files
committed
Add group test and fix failure
Signed-off-by: Filip Petkovski <[email protected]>
1 parent 39345f5 commit 1216a86

File tree

2 files changed

+14
-3
lines changed

2 files changed

+14
-3
lines changed

engine/engine_test.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,10 +1103,17 @@ func TestQueriesAgainstOldEngine(t *testing.T) {
11031103
{
11041104
name: "group",
11051105
load: `load 30s
1106-
http_requests_total{pod="nginx-1"} 1+1x15
1107-
http_requests_total{pod="nginx-2"} 1+2x18`,
1106+
http_requests_total{pod="nginx-1"} 2+1x15
1107+
http_requests_total{pod="nginx-2"} 2+2x18`,
11081108
query: `group(http_requests_total)`,
11091109
},
1110+
{
1111+
name: "group by ",
1112+
load: `load 30s
1113+
http_requests_total{pod="nginx-1"} 2+1x15
1114+
http_requests_total{pod="nginx-2"} 2+2x18`,
1115+
query: `group by (pod) (http_requests_total)`,
1116+
},
11101117
{
11111118
name: "resets",
11121119
load: `load 30s

execution/aggregate/accumulator.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ func (s *sumAcc) Reset(_ float64) {
7979
}
8080

8181
type genericAcc struct {
82+
zeroVal float64
8283
value float64
8384
hasValue bool
8485
aggregate func(float64, float64) float64
@@ -112,20 +113,23 @@ func groupVecAggregate(_ []float64, _ []*histogram.FloatHistogram) float64 {
112113

113114
func newMaxAcc() *genericAcc {
114115
return &genericAcc{
116+
zeroVal: math.MinInt64,
115117
aggregate: maxAggregate,
116118
vectorAggregate: maxVecAggregate,
117119
}
118120
}
119121

120122
func newMinAcc() *genericAcc {
121123
return &genericAcc{
124+
zeroVal: math.MaxInt64,
122125
aggregate: minAggregate,
123126
vectorAggregate: minVecAggregate,
124127
}
125128
}
126129

127130
func newGroupAcc() *genericAcc {
128131
return &genericAcc{
132+
zeroVal: 1,
129133
aggregate: groupAggregate,
130134
vectorAggregate: groupVecAggregate,
131135
}
@@ -136,7 +140,7 @@ func (g *genericAcc) Add(v float64, _ *histogram.FloatHistogram) {
136140
return
137141
}
138142
if !g.hasValue {
139-
g.value = v
143+
g.value = g.aggregate(g.zeroVal, v)
140144
g.hasValue = true
141145
return
142146
}

0 commit comments

Comments
 (0)