Skip to content

Commit

Permalink
Fix null results
Browse files Browse the repository at this point in the history
  • Loading branch information
alanprot committed Apr 25, 2024
1 parent 0305490 commit c4a5e4e
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 4 deletions.
8 changes: 4 additions & 4 deletions promql/engine.go
Expand Up @@ -722,7 +722,7 @@ func (ng *Engine) execEvalStmt(ctx context.Context, query *query, s *parser.Eval
return nil, warnings, err
}

var mat Matrix
mat := Matrix{}

Check failure on line 725 in promql/engine.go

View workflow job for this annotation

GitHub Actions / golangci-lint

SA4006: this value of `mat` is never used (staticcheck)

switch result := val.(type) {
case Matrix:
Expand Down 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
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 c4a5e4e

Please sign in to comment.