fix pre gui queries shortcircuit

This commit is contained in:
Sven Klemm
2018-07-21 09:57:42 +02:00
parent 9f0b4e0aa7
commit 84d7743939
2 changed files with 15 additions and 2 deletions

View File

@@ -170,6 +170,8 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
rowCount := 0
timeIndex := -1
metricIndex := -1
metricPrefix := false
metricPrefixValue := ""
// 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
@@ -179,6 +181,10 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
timeIndex = i
case "metric":
metricIndex = i
// use metric column as prefix with multiple value columns
if len(columnNames) > 3 {
metricPrefix = true
}
default:
if metricIndex == -1 {
switch columnTypes[i].DatabaseTypeName() {
@@ -234,7 +240,11 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
if metricIndex >= 0 {
if columnValue, ok := values[metricIndex].(string); ok {
if metricPrefix {
metricPrefixValue = columnValue
} else {
metric = columnValue
}
} else {
return fmt.Errorf("Column metric must be of type char,varchar or text, got: %T %v", values[metricIndex], values[metricIndex])
}
@@ -251,6 +261,8 @@ func (e PostgresQueryEndpoint) transformToTimeSeries(query *tsdb.Query, rows *co
if metricIndex == -1 {
metric = col
} else if metricPrefix {
metric = metricPrefixValue + " " + col
}
series, exist := pointsBySeries[metric]

View File

@@ -77,7 +77,8 @@ export default class PostgresQuery {
render(interpolate?) {
let target = this.target;
if (!('table' in this.target)) {
// new query with no table set yet
if (!this.target.rawQuery && !('table' in this.target)) {
return '';
}