Browse Source

promql: remove histogramMean from groupedAggregation

Re-use histogramValue since we don't need them separately.

Tidy up initialization.

Signed-off-by: Bryan Boreham <bjboreham@gmail.com>
pull/13744/head
Bryan Boreham 9 months ago
parent
commit
5e3914a27c
  1. 29
      promql/engine.go

29
promql/engine.go

@ -2733,7 +2733,6 @@ type groupedAggregation struct {
floatValue float64 floatValue float64
histogramValue *histogram.FloatHistogram histogramValue *histogram.FloatHistogram
floatMean float64 floatMean float64
histogramMean *histogram.FloatHistogram
groupCount int groupCount int
heap vectorByValueHeap heap vectorByValueHeap
reverseHeap vectorByReverseValueHeap reverseHeap vectorByReverseValueHeap
@ -2762,20 +2761,14 @@ func (ev *evaluator) aggregation(e *parser.AggregateExpr, q float64, inputMatrix
floatMean: f, floatMean: f,
groupCount: 1, groupCount: 1,
} }
switch {
case h == nil:
group.hasFloat = true
case op == parser.SUM:
group.histogramValue = h.Copy()
group.hasHistogram = true
case op == parser.AVG:
group.histogramMean = h.Copy()
group.hasHistogram = true
case op == parser.STDVAR || op == parser.STDDEV:
group.groupCount = 0
}
switch op { switch op {
case parser.SUM, parser.AVG:
if h == nil {
group.hasFloat = true
} else {
group.histogramValue = h.Copy()
group.hasHistogram = true
}
case parser.STDVAR, parser.STDDEV: case parser.STDVAR, parser.STDDEV:
group.floatValue = 0 group.floatValue = 0
case parser.QUANTILE: case parser.QUANTILE:
@ -2807,11 +2800,11 @@ func (ev *evaluator) aggregation(e *parser.AggregateExpr, q float64, inputMatrix
group.groupCount++ group.groupCount++
if h != nil { if h != nil {
group.hasHistogram = true group.hasHistogram = true
if group.histogramMean != nil { if group.histogramValue != nil {
left := h.Copy().Div(float64(group.groupCount)) left := h.Copy().Div(float64(group.groupCount))
right := group.histogramMean.Copy().Div(float64(group.groupCount)) right := group.histogramValue.Copy().Div(float64(group.groupCount))
toAdd := left.Sub(right) toAdd := left.Sub(right)
group.histogramMean.Add(toAdd) group.histogramValue.Add(toAdd)
} }
// Otherwise the aggregation contained floats // Otherwise the aggregation contained floats
// previously and will be invalid anyway. No // previously and will be invalid anyway. No
@ -2886,7 +2879,7 @@ func (ev *evaluator) aggregation(e *parser.AggregateExpr, q float64, inputMatrix
continue continue
} }
if aggr.hasHistogram { if aggr.hasHistogram {
aggr.histogramValue = aggr.histogramMean.Compact(0) aggr.histogramValue = aggr.histogramValue.Compact(0)
} else { } else {
aggr.floatValue = aggr.floatMean aggr.floatValue = aggr.floatMean
} }

Loading…
Cancel
Save