diff --git a/pkg/logql/shardmapper.go b/pkg/logql/shardmapper.go index e55b01504537f..05504be6dd340 100644 --- a/pkg/logql/shardmapper.go +++ b/pkg/logql/shardmapper.go @@ -397,13 +397,18 @@ func (m ShardMapper) mapRangeAggregationExpr(expr *syntax.RangeAggregationExpr, return m.mapSampleExpr(expr, r) } + grouping := expr.Grouping + if grouping == nil { + grouping = &syntax.Grouping{Without: true} + } + // avg_over_time() by (foo) -> sum by (foo) (sum_over_time()) / sum by (foo) (count_over_time()) lhs, lhsBytesPerShard, err := m.mapVectorAggregationExpr(&syntax.VectorAggregationExpr{ Left: &syntax.RangeAggregationExpr{ Left: expr.Left, Operation: syntax.OpRangeTypeSum, }, - Grouping: expr.Grouping, + Grouping: grouping, Operation: syntax.OpTypeSum, }, r, false) if err != nil { @@ -421,7 +426,7 @@ func (m ShardMapper) mapRangeAggregationExpr(expr *syntax.RangeAggregationExpr, Left: countOverTimeSelector, Operation: syntax.OpRangeTypeCount, }, - Grouping: expr.Grouping, + Grouping: grouping, Operation: syntax.OpTypeSum, }, r, false) if err != nil {