From e5f667537c94dbd1e5ad70d766c0c27ea5cb8830 Mon Sep 17 00:00:00 2001 From: Bryan Boreham Date: Wed, 17 Jan 2024 10:57:02 +0000 Subject: [PATCH] promql: refactor: initialize aggregation before storing in map This seems more consistent to me. Signed-off-by: Bryan Boreham --- promql/engine.go | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/promql/engine.go b/promql/engine.go index 9074912d6..0a2c5ff3f 100644 --- a/promql/engine.go +++ b/promql/engine.go @@ -2686,9 +2686,6 @@ func (ev *evaluator) aggregation(e *parser.AggregateExpr, grouping []string, par newAgg.groupCount = 0 } - result[groupingKey] = newAgg - orderedResult = append(orderedResult, newAgg) - inputVecLen := int64(len(vec)) resultSize := k switch { @@ -2699,22 +2696,25 @@ func (ev *evaluator) aggregation(e *parser.AggregateExpr, grouping []string, par } switch op { case parser.STDVAR, parser.STDDEV: - result[groupingKey].floatValue = 0 + newAgg.floatValue = 0 case parser.TOPK, parser.QUANTILE: - result[groupingKey].heap = make(vectorByValueHeap, 1, resultSize) - result[groupingKey].heap[0] = Sample{ + newAgg.heap = make(vectorByValueHeap, 1, resultSize) + newAgg.heap[0] = Sample{ F: s.F, Metric: s.Metric, } case parser.BOTTOMK: - result[groupingKey].reverseHeap = make(vectorByReverseValueHeap, 1, resultSize) - result[groupingKey].reverseHeap[0] = Sample{ + newAgg.reverseHeap = make(vectorByReverseValueHeap, 1, resultSize) + newAgg.reverseHeap[0] = Sample{ F: s.F, Metric: s.Metric, } case parser.GROUP: - result[groupingKey].floatValue = 1 + newAgg.floatValue = 1 } + + result[groupingKey] = newAgg + orderedResult = append(orderedResult, newAgg) continue }