Postgres/MySQL/MSSQL: Fix name of time field should be named Time for time series queries (#36720)

Name of time field changed in v8 for time series queries from Time to the name of the selected 
time column, i.e. time or time_sec. These changes should make sure that the name of time field 
is always returned as Time for time series queries.

Fixes #36059

Co-authored-by: Ryan McKinley <ryantxu@gmail.com>
This commit is contained in:
Marcus Efraimsson 2021-07-14 11:29:51 +02:00 committed by GitHub
parent 92801d5fa1
commit 10c892fa5b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 6 additions and 0 deletions

View File

@ -373,6 +373,7 @@ func TestMySQL(t *testing.T) {
frames, _ := queryResult.Dataframes.Decoded()
require.Len(t, frames, 1)
require.Equal(t, data.TimeSeriesTimeFieldName, frames[0].Fields[0].Name)
require.Equal(t, 7, frames[0].Fields[0].Len())
require.Equal(t, 1.5, *frames[0].Fields[1].At(3).(*float64))
})
@ -505,6 +506,7 @@ func TestMySQL(t *testing.T) {
frames, err := queryResult.Dataframes.Decoded()
require.NoError(t, err)
require.Len(t, frames, 1)
require.Equal(t, data.TimeSeriesTimeFieldName, frames[0].Fields[0].Name)
require.True(t, tInitial.Equal(*frames[0].Fields[0].At(0).(*time.Time)))
})

View File

@ -283,6 +283,10 @@ func (e *dataPlugin) executeQuery(query plugins.DataSubQuery, wg *sync.WaitGroup
errAppendDebug("db has no time column", errors.New("no time column found"), interpolatedQuery)
return
}
// Make sure to name the time field 'Time' to be backward compatible with Grafana pre-v8.
frame.Fields[qm.timeIndex].Name = data.TimeSeriesTimeFieldName
for i := range qm.columnNames {
if i == qm.timeIndex || i == qm.metricIndex {
continue