flux icon indicating copy to clipboard operation
flux copied to clipboard

Fill function not working

Open dan-hughes opened this issue 6 years ago • 1 comments

I have a measurement being updated every 9 minutes. I have tried using the fill function to replicate the IFQL fill(previous) behavior but it doesn't seem create the data specified by the window.

Expected: start and stop should be for every minute in the range (not just a minute when there is a value stored) with the value using the previous value if missing.

Flux script tested on 2.0 Alpha1:

from(bucket: "test")
  |> range(start: -1d )
  |> filter({filter removed})
  |> window(every: 1m)
  |> fill(usePrevious:true)
  |> last()

dan-hughes avatar Jan 25 '19 18:01 dan-hughes

I have a scenario like this.

I want to sum the points of both (or more) symbols each 20 seconds (or any other interval). Below are the raw points stored in a single measurement grouped by symbol. The second query is the one I came up with to calculate sum(sum() gives me same issue as well).

select last(bs) from table where symbol=<1> or symbol=<2> and time>=1592833320000ms and time<=1592833440000ms group by symbol, time(20s)

name: table tags: symbol=<1> time last

2020-06-22T13:42:00Z 84 2020-06-22T13:42:20Z 94 2020-06-22T13:42:40Z 95 2020-06-22T13:43:00Z 87 2020-06-22T13:43:20Z 76 2020-06-22T13:43:40Z 77 2020-06-22T13:44:00Z

name: table tags: symbol=<2> time last

2020-06-22T13:42:00Z 288 2020-06-22T13:42:20Z 286 2020-06-22T13:42:40Z 282 2020-06-22T13:43:00Z 2020-06-22T13:43:20Z 312 2020-06-22T13:43:40Z 330 2020-06-22T13:44:00Z

check out how 13:43:00Z has no value; fill(previous) works if this was a single query and will copy over 282 from above. But when I group by both symbols the value will just be 0 for this time stamp and the mean value will go way down at this time.

select mean(lbs) from (select last(bs) as lbs from table where symbol=<1> or symbol=<2> and time>=1592833320000ms and time<=1592833440000ms group by symbol, time(20s)) group by time(20s) limit 10 name: table time mean

2020-06-22T13:42:00Z 372 2020-06-22T13:42:20Z 380 2020-06-22T13:42:40Z 377 2020-06-22T13:43:00Z 87 2020-06-22T13:43:20Z 388 2020-06-22T13:43:40Z 407 2020-06-22T13:44:00Z

Having a fill(previous) in the inner query does not work. Question is, how can I take the last value of the missing groups into the mean calculation.

I even tried using FLUX with the following query, but still see same issue. from(bucket: "db/rp") |> range($range) |> filter(fn: (r) => r._measurement == "table" and (r._field == "") and r.symbol=~ /^[[Symbol]]$/) |> aggregateWindow(every: 1m, createEmpty: true, fn:sum) |> fill(usePrevious: true) |> group(columns: ["_time", "_field"]) |> sum() |> group(columns: ["_measurement", "_field"])

Let me know if there is any workaround for this issue. Thanks!

reichunter1656 avatar Jun 30 '20 22:06 reichunter1656

This issue has had no recent activity and will be closed soon.

github-actions[bot] avatar Sep 15 '24 01:09 github-actions[bot]