Description
hi,
we have an issue reported for the bigquery-datasource (which uses sqlds), about a difference in behavior between bigquery-plugin and postgres. i'd like to discuss what we think about this, is this that we should change, add some optional-thing, or we should not have.
the postgres/mysq/mssql does a special handling for the following case:
- format=time_series
- exactly 3 db-columns
- the string-column is named
metric
for example, this query:
SELECT CURRENT_TIMESTAMP as time, 'sku' AS metric, 1 AS cost
the output from sqlds is a dataframe with 2 fields: the time-field and the value-field. this is about the value field.
sqlds: value-field has: name=cost
, labels={metric:sku}
postgres: value-field has: name=sku
, no labels
this will cause the legend-field in the visualisation to change:
sqlds: legend has cost sku
postgres: legend has sku
this can be a nicer visual representation in some cases (after all, if you only have 1 value-db-column, you don't care about it's name).
the postgres code: https://github.com/grafana/grafana/blob/86c618a6d62dcd2f33983fb0cecbad71781da8c3/pkg/tsdb/sqleng/sql_engine.go#L340-L354
i wonder what do you think about this. some arguments:
- pro:
- this may be a very common time-series query (don't know), so making it more ergonomical may be a good thing
- we already have some assumptions about the data in the
format=time_series
case
- con:
- not doing it makes the behavior simpler, easier to understand, this special-behavior is not really discoverable
- changing the behavior breaks backward compatibility
- there is a workaround: use a transform (labels-to-fields or organize-by-name)
what do you think?
(one alternative is to do the change in the visualisation (timeseries in this case))
for reference, here's a list of various queries, and the legend-comparison between postgres and bigquery:
SELECT CURRENT_TIMESTAMP as time, 'sku' AS something, 1 AS cost
bigquery: cost sku
postgres: cost sku
SELECT CURRENT_TIMESTAMP as time, 'sku' AS metric, 1 AS cost
bigquery: cost sku
postgres: sku
SELECT CURRENT_TIMESTAMP as time, 'sku' AS metric, 'xyz' as thing, 1 AS cost
bigquery: cost {metric="sku", thing="xyz"}
postgres: cost {metric="sku", thing="xyz"}