Divide by 0 for some fields (not getting data for any fields)

Hello

Anybody get issues with divided by 0 ?

I am getting data back when calculating x+y but no data when using x/y. Some rows are y = 0 but I am not getting any data and getting error "InfluxDB Error: Internal Server Error".

  1. How to overcome this ? How to not send 0 values for calculation ?
  2. How can I add missing value (_value) on the first record in every aggregate window ?
    ,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,,2020-01-20T11:40:00Z

Thanks a lot,

Query (x+y)

cycle = from(bucket: "test")
  |> range($range)
  |> filter(fn: (r) =>
    r._measurement == "fautest" and
    r.trigger =~ /cycle|interval/ and
    r._field == "countfld")
|> group(columns: ["_measurement", "_start", "_field"])
|> aggregateWindow(every: 5m, fn: sum)

reject = from(bucket: "test")
  |> range($range)
  |> filter(fn: (r) =>
    r._measurement == "fautest" and
    r.trigger =~ /reject|interval/ and
    r._field == "countfld")
|> group(columns: ["_measurement", "_start", "_field"])
|> aggregateWindow(every: 5m, fn: sum)

multiply = (x, y) => (x + y)

join(tables:{reject:reject, cycle:cycle}, on:["_time"])
|> map(fn:(r) => ({
 _time: r._time, _value: multiply(x:float(v: r._value_cycle), y:float(v: r._value_reject)) }))
|> aggregateWindow(every: 5m, fn: sum)

Query result (x+y)

#datatype,string,long,dateTime:RFC3339,dateTime:RFC3339,double,dateTime:RFC3339
#group,false,false,true,true,false,false
#default,_result,,,,,
,result,table,_start,_stop,_value,_time
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,,2020-01-20T11:40:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,0,2020-01-20T11:45:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,0,2020-01-20T11:50:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,5,2020-01-20T11:55:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,0,2020-01-20T12:00:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,9,2020-01-20T12:05:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,2,2020-01-20T12:10:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,0,2020-01-20T12:15:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,0,2020-01-20T12:20:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,0,2020-01-20T12:25:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,2,2020-01-20T12:30:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,1,2020-01-20T12:35:00Z
,,0,2020-01-20T11:39:14.027361277Z,2020-01-20T12:39:14.027361277Z,3,2020-01-20T12:39:14.027361277Z

If anybody else having similar issue, I use a workaround by taking out 0 values before making calculation and further steps.

cycle = from(bucket: "test")
  |> range($range)
  |> filter(fn: (r) =>
    r._measurement == "fautest" and
    r.trigger =~ /cycle|interval/ and
    r._field == "countfld")
|> group(columns: ["_measurement", "_start", "_field"])
|> aggregateWindow(every: 5m, fn: sum)

reject = from(bucket: "test")
  |> range($range)
  |> filter(fn: (r) =>
    r._measurement == "fautest" and
    r.trigger =~ /reject|interval/ and
    r._field == "countfld")
|> group(columns: ["_measurement", "_start", "_field"])
|> aggregateWindow(every: 5m, fn: sum)

multiply = (x, y) => ((x - y) / (x)) * 100.00

join(tables:{reject:reject, cycle:cycle}, on:["_time"])
|> map(fn:(r) => ({
     r with _time: r._time,
     _value_zero: if r._value_cycle == 0 then "reduce"
     else "keep"
     })
   )
|> filter(fn: (r) =>
    r._value_zero == "keep")
|> map(fn:(r) => ({
     _time: r._time,
     _value: multiply(x:float(v: r._value_cycle), y:float(v: r._value_reject))
     })
   )