|
|
@ -2138,6 +2138,7 @@ type groupedAggregation struct {
|
|
|
|
func (ev *evaluator) aggregation(op parser.ItemType, grouping []string, without bool, param interface{}, vec Vector, seriesHelper []EvalSeriesHelper, enh *EvalNodeHelper) Vector {
|
|
|
|
func (ev *evaluator) aggregation(op parser.ItemType, grouping []string, without bool, param interface{}, vec Vector, seriesHelper []EvalSeriesHelper, enh *EvalNodeHelper) Vector {
|
|
|
|
|
|
|
|
|
|
|
|
result := map[uint64]*groupedAggregation{}
|
|
|
|
result := map[uint64]*groupedAggregation{}
|
|
|
|
|
|
|
|
orderedResult := []*groupedAggregation{}
|
|
|
|
var k int64
|
|
|
|
var k int64
|
|
|
|
if op == parser.TOPK || op == parser.BOTTOMK {
|
|
|
|
if op == parser.TOPK || op == parser.BOTTOMK {
|
|
|
|
f := param.(float64)
|
|
|
|
f := param.(float64)
|
|
|
@ -2206,12 +2207,16 @@ func (ev *evaluator) aggregation(op parser.ItemType, grouping []string, without
|
|
|
|
} else {
|
|
|
|
} else {
|
|
|
|
m = metric.WithLabels(grouping...)
|
|
|
|
m = metric.WithLabels(grouping...)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
result[groupingKey] = &groupedAggregation{
|
|
|
|
newAgg := &groupedAggregation{
|
|
|
|
labels: m,
|
|
|
|
labels: m,
|
|
|
|
value: s.V,
|
|
|
|
value: s.V,
|
|
|
|
mean: s.V,
|
|
|
|
mean: s.V,
|
|
|
|
groupCount: 1,
|
|
|
|
groupCount: 1,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
result[groupingKey] = newAgg
|
|
|
|
|
|
|
|
orderedResult = append(orderedResult, newAgg)
|
|
|
|
|
|
|
|
|
|
|
|
inputVecLen := int64(len(vec))
|
|
|
|
inputVecLen := int64(len(vec))
|
|
|
|
resultSize := k
|
|
|
|
resultSize := k
|
|
|
|
if k > inputVecLen {
|
|
|
|
if k > inputVecLen {
|
|
|
@ -2333,7 +2338,7 @@ func (ev *evaluator) aggregation(op parser.ItemType, grouping []string, without
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Construct the result Vector from the aggregated groups.
|
|
|
|
// Construct the result Vector from the aggregated groups.
|
|
|
|
for _, aggr := range result {
|
|
|
|
for _, aggr := range orderedResult {
|
|
|
|
switch op {
|
|
|
|
switch op {
|
|
|
|
case parser.AVG:
|
|
|
|
case parser.AVG:
|
|
|
|
aggr.value = aggr.mean
|
|
|
|
aggr.value = aggr.mean
|
|
|
|