Datasource: Fix missing raw SQL query in Query Inspector when query returns zero rows (#67844)

* baldm0mma/issue5799/ add empty frame with all meta data

* baldm0mma/issue5799/ add null test

* write an integration test around query results with empty rows

* baldm0mma/issue5799/ add tests to mssql and postgres

* remove use of apparently reserved keyword in mysql8

* baldm0mma/issue5799

* baldm0mma/issue5799/ update tests

* baldm0mma/issue5799/ update test structs

* baldm0mma/issue5799/ update annotation

---------

Co-authored-by: Michael Mandrus <michael.mandrus@grafana.com>
This commit is contained in:
Jev Forsberg
2023-05-09 08:29:02 -06:00
committed by GitHub
parent 8e752439c6
commit 86228ba1a0
4 changed files with 138 additions and 2 deletions

View File

@ -312,9 +312,13 @@ func (e *DataSourceHandler) executeQuery(query backend.DataQuery, wg *sync.WaitG
frame.Meta.ExecutedQueryString = interpolatedQuery
// If no rows were returned, no point checking anything else.
// If no rows were returned, clear any previously set `Fields` with a single empty `data.Field` slice.
// Then assign `queryResult.dataResponse.Frames` the current single frame with that single empty Field.
// This assures 1) our visualization doesn't display unwanted empty fields, and also that 2)
// additionally-needed frame data stays intact and is correctly passed to our visulization.
if frame.Rows() == 0 {
queryResult.dataResponse.Frames = data.Frames{}
frame.Fields = []*data.Field{}
queryResult.dataResponse.Frames = data.Frames{frame}
ch <- queryResult
return
}