The most efficient way to do this is with the following structure:
data = from() |> range() |> filter|>
open = data |> aggregateWindow(fn: first)
close = data |> aggregateWindow(fn: last)
high = data |> aggregateWindow(fn: max)
low = data |> aggregateWindow(fn: min)
However, aggwindow is a pushdown function. Pushdowns are functions or function combinations that push data operations to the underlying data source rather than operating on data in memory.
So it’s possible that your approach is just as efficient. Id have to use the Flux profiler to verify:
This way you don’t have to query for the data each time.
No it’s not possible to use one aggregateWindow() function because data in flux is pipe-forwarded and aggWindow doesn’t support simultaneous outputs/multiple params for fn inputs.
You could create a feature request though here: https://github.com/influxdata/flux