Postgres/MySQL/MSSQL: Adds support for region annotations (#20752)

Adds support for region annotations in Postgres, MySQL and 
MSSQL data sources by adding a column named timeend to 
annotation query.

Co-Authored-By: Diana Payton <52059945+oddlittlebird@users.noreply.github.com>

Closes #20918
Ref #10589
This commit is contained in:
Jerry Ylilammi
2019-12-13 18:25:36 +02:00
committed by Marcus Efraimsson
parent f65da93d72
commit e27ab89aed
13 changed files with 249 additions and 28 deletions

View File

@ -56,6 +56,8 @@ var NewXormEngine = func(driverName string, connectionString string) (*xorm.Engi
return xorm.NewEngine(driverName, connectionString)
}
const timeEndColumnName = "timeend"
type sqlQueryEndpoint struct {
macroEngine SqlMacroEngine
queryResultTransformer SqlQueryResultTransformer
@ -218,6 +220,7 @@ func (e *sqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows,
rowCount := 0
timeIndex := -1
timeEndIndex := -1
table := &tsdb.Table{
Columns: make([]tsdb.TableColumn, columnCount),
@ -232,6 +235,11 @@ func (e *sqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows,
timeIndex = i
break
}
if timeIndex >= 0 && name == timeEndColumnName {
timeEndIndex = i
break
}
}
}
@ -250,10 +258,11 @@ func (e *sqlQueryEndpoint) transformToTable(query *tsdb.Query, rows *core.Rows,
return err
}
// converts column named time to unix timestamp in milliseconds
// converts column named time and timeend to unix timestamp in milliseconds
// to make native mssql datetime types and epoch dates work in
// annotation and table queries.
ConvertSqlTimeColumnToEpochMs(values, timeIndex)
ConvertSqlTimeColumnToEpochMs(values, timeEndIndex)
table.Rows = append(table.Rows, values)
}