Commit 373389c9 by Sven Klemm Committed by Daniel Lee

treat any text column in timeseries query as metric name unless column (#9985)

named metric is present
parent 48d9d0d3
...@@ -142,8 +142,13 @@ func (e PostgresQueryEndpoint) getTypedRowData(rows *core.Rows) (tsdb.RowValues, ...@@ -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 ...@@ -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
}
}
} }
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment