Is it possible to use aggregateWindow() with different functions?

Hi,

Suppose I have a stock price data sampled every minute.

I’d like to aggregate the data in a 1 day window to a new bucket such that the fields in the new bucket will be defined in the following way:

  1. Open - The first price in each window
  2. Close - The last price in each window
  3. High - The maximum price in each window
  4. Low - The minimum price in each window

Of course I can iterate the data four times the calculate what I need but I guess it is not the most efficient way to do it.

Is it possible to use one aggregateWindow() function in order to achieve this goal?

Thanks

Hello @amitrotner,

The most efficient way to do this is with the following structure:

data = from() |> range() |> filter|>

open = data |> aggregateWindow(fn: first)
|> to()

close = data |> aggregateWindow(fn: last)
|> to()

high = data |> aggregateWindow(fn: max)
|> to()

low = data |> aggregateWindow(fn: min)
|> to()

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

1 Like