mirror of
https://github.com/grafana/grafana.git
synced 2025-02-25 18:55:37 -06:00
treat any text column in timeseries query as metric name unless column (#9985)
named metric is present
This commit is contained in:
@@ -142,8 +142,13 @@ func (e PostgresQueryEndpoint) getTypedRowData(rows *core.Rows) (tsdb.RowValues,
|
|||||||
func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult) error {
|
func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *core.Rows, result *tsdb.QueryResult) error {
|
||||||
pointsBySeries := make(map[string]*tsdb.TimeSeries)
|
pointsBySeries := make(map[string]*tsdb.TimeSeries)
|
||||||
seriesByQueryOrder := list.New()
|
seriesByQueryOrder := list.New()
|
||||||
columnNames, err := rows.Columns()
|
|
||||||
|
|
||||||
|
columnNames, err := rows.Columns()
|
||||||
|
if err != nil {
|
||||||
|
return err
|
||||||
|
}
|
||||||
|
|
||||||
|
columnTypes, err := rows.ColumnTypes()
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
@@ -153,13 +158,21 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
|
|||||||
timeIndex := -1
|
timeIndex := -1
|
||||||
metricIndex := -1
|
metricIndex := -1
|
||||||
|
|
||||||
// check columns of resultset
|
// check columns of resultset: a column named time is mandatory
|
||||||
|
// the first text column is treated as metric name unless a column named metric is present
|
||||||
for i, col := range columnNames {
|
for i, col := range columnNames {
|
||||||
switch col {
|
switch col {
|
||||||
case "time":
|
case "time":
|
||||||
timeIndex = i
|
timeIndex = i
|
||||||
case "metric":
|
case "metric":
|
||||||
metricIndex = i
|
metricIndex = i
|
||||||
|
default:
|
||||||
|
if metricIndex == -1 {
|
||||||
|
switch columnTypes[i].DatabaseTypeName() {
|
||||||
|
case "UNKNOWN", "TEXT", "VARCHAR", "CHAR":
|
||||||
|
metricIndex = i
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user