Skip to content

Commit

Permalink
Fix null results
Browse files Browse the repository at this point in the history
Signed-off-by: alanprot <alanprot@gmail.com>
  • Loading branch information
alanprot committed Apr 25, 2024
1 parent 0305490 commit b1979db
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 3 deletions.
6 changes: 3 additions & 3 deletions promql/engine.go
Original file line number Diff line number Diff line change
Expand Up @@ -1298,7 +1298,7 @@ func (ev *evaluator) rangeEvalAgg(aggExpr *parser.AggregateExpr, sortedGrouping
buf := make([]byte, 0, 1024)
groupToResultIndex := make(map[uint64]int)
seriesToResult := make([]int, len(inputMatrix))
var result Matrix
result := Matrix{}

groupCount := 0
for si, series := range inputMatrix {
Expand Down Expand Up @@ -1331,7 +1331,7 @@ func (ev *evaluator) rangeEvalAgg(aggExpr *parser.AggregateExpr, sortedGrouping
k = len(inputMatrix)
}
if k < 1 {
return nil, warnings
return Matrix{}, warnings
}
seriess = make(map[uint64]Series, len(inputMatrix)) // Output series by series hash.
case parser.QUANTILE:
Expand Down Expand Up @@ -2983,7 +2983,7 @@ func (ev *evaluator) aggregationK(e *parser.AggregateExpr, k int, inputMatrix Ma

// Construct the result from the aggregated groups.
numSteps := int((ev.endTimestamp-ev.startTimestamp)/ev.interval) + 1
var mat Matrix
mat := Matrix{}
if ev.endTimestamp == ev.startTimestamp {
mat = make(Matrix, 0, len(groups))
}
Expand Down
15 changes: 15 additions & 0 deletions web/api/v1/api_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1171,6 +1171,21 @@ func testEndpoints(t *testing.T, api *API, tr *testTargetRetriever, es storage.E
},
},
},
// Test empty matrix result
{
endpoint: api.queryRange,
query: url.Values{
"query": []string{"bottomk(2, notExists)"},
"start": []string{"0"},
"end": []string{"2"},
"step": []string{"1"},
},
response: &QueryData{
ResultType: parser.ValueTypeMatrix,
Result: promql.Matrix{},
},
responseAsJSON: `{"resultType":"matrix","result":[]}`,
},
// Missing query params in range queries.
{
endpoint: api.queryRange,
Expand Down

0 comments on commit b1979db

Please sign in to comment.