Skip to content
This repository has been archived by the owner on Dec 11, 2020. It is now read-only.

union results in 2 datasets #125

Open
SGStino opened this issue Jul 30, 2020 · 1 comment
Open

union results in 2 datasets #125

SGStino opened this issue Jul 30, 2020 · 1 comment

Comments

@SGStino
Copy link

SGStino commented Jul 30, 2020

previous = from(bucket: "Bucket")
  |> range(stop: v.timeRangeStart, start: 0) 
  |> filter(fn: (r) => r["_measurement"] == "Tags.PLC_252.TANK1.LEVEL")
  |> filter(fn: (r) => r["_field"] == "value")  
  |> last()
  
current = from(bucket: "Bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Tags.PLC_252.TANK1.LEVEL")
  |> filter(fn: (r) => r["_field"] == "value")  
  |> aggregateWindow(every: v.windowPeriod, fn: last)

union(tables: [previous, current])  
  |> set(key:"_field", value:"test") 
  |> yield()

This results in 2 series in grafana, both named "test". One containing a single value, the other one containing the range.

For grafana, this is equivalent:

from(bucket: "Bucket")
  |> range(stop: v.timeRangeStart, start: 0) 
  |> filter(fn: (r) => r["_measurement"] == "Tags.PLC_252.TANK1.LEVEL")
  |> filter(fn: (r) => r["_field"] == "value")  
  |> last()
  |> yield(name:"A")

from(bucket: "Bucket")
  |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
  |> filter(fn: (r) => r["_measurement"] == "Tags.PLC_252.TANK1.LEVEL")
  |> filter(fn: (r) => r["_field"] == "value")  
  |> aggregateWindow(every: 1s, fn: last)
  |> yield(name:"B")

To get the desired result, i need to use grafana's merge transform. But if there are multiple queries, they will all get merged instead. This means that it seems impossible to have multiple queries in the same panel?

@SGStino
Copy link
Author

SGStino commented Jul 30, 2020

To remedy, it would seem to be as simple of piping the union to window(every: inf)

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant