I have been wrangling with a time grouping issue in influxDB using the flux query language. I can illustrate with generated data, one entry per day from 2021-01-01 to 2021-01-05.
import "generate"
data = generate.from(
count: 5,
fn: (n) => n + 1,
start: 2021-01-01T00:00:00Z,
stop: 2021-01-06T00:00:00Z,
)
data
|> range(start: 2021-01-01T00:00:00Z, stop: 2021-01-05T05:00:00Z)
that generates:
| _table | _value | _start | _stop | _time |
|---|---|---|---|---|
| 0 | 1 | 2021-01-01T00:00:00.000Z | 2021-01-05T23:59:00.000Z | 2021-01-01T00:00:00.000Z |
| 0 | 2 | 2021-01-01T00:00:00.000Z | 2021-01-05T23:59:00.000Z | 2021-01-02T00:00:00.000Z |
| 0 | 3 | 2021-01-01T00:00:00.000Z | 2021-01-05T23:59:00.000Z | 2021-01-03T00:00:00.000Z |
| 0 | 4 | 2021-01-01T00:00:00.000Z | 2021-01-05T23:59:00.000Z | 2021-01-04T00:00:00.000Z |
| 0 | 5 | 2021-01-01T00:00:00.000Z | 2021-01-05T23:59:00.000Z | 2021-01-05T00:00:00.000Z |
now I query the data and aggregate per day
import "generate"
data = generate.from(
count: 5,
fn: (n) => n + 1,
start: 2021-01-01T00:00:00Z,
stop: 2021-01-06T00:00:00Z,
)
data
|> range(start: 2021-01-01T00:00:00Z, stop: 2021-01-05T23:59:00Z)
|> aggregateWindow(every: 1d, fn: sum, createEmpty: false)
I get this
| _table | _value | _start | _stop | _time |
|---|---|---|---|---|
| 0 | 1 | 2021-01-01T00:00:00.000Z | 2021-01-05T23:59:00.000Z | 2021-01-02T00:00:00.000Z |
| 0 | 2 | 2021-01-01T00:00:00.000Z | 2021-01-05T23:59:00.000Z | 2021-01-03T00:00:00.000Z |
| 0 | 3 | 2021-01-01T00:00:00.000Z | 2021-01-05T23:59:00.000Z | 2021-01-04T00:00:00.000Z |
| 0 | 4 | 2021-01-01T00:00:00.000Z | 2021-01-05T23:59:00.000Z | 2021-01-05T00:00:00.000Z |
| 0 | 5 | 2021-01-01T00:00:00.000Z | 2021-01-05T23:59:00.000Z | 2021-01-05T23:59:00.000Z |
the first time is 2021-01-02T00:00:00.000Z and not 2021-01-01 and the two last entries cover the same day 2021-01-05.
how can I get the entries per day as below using flux:
- 2021-01-01 - 1
- 2021-01-02 - 2
- 2021-01-03 - 3
- 2021-01-04 - 4
- 2021-01-05 - 5