Conditional logic with float not working

Conditional logic with integer working just fine but not working with float, is my interpreting of float in condition wrong ?

I tried all possible scenarios for float brackets but no success.

Integer conditional logic - results OK

join(tables:{reject:reject, cycle:cycle}, on:["_start"])
|> map(fn:(r) => ({
     _value: if r._value_cycle == 0 then 5 else r._value_cycle / r._value_reject
   }))

Without conditional logic, float works fine - OK

quality = join(tables:{reject:reject, cycle:cycle}, on:["_start"])
|> map(fn:(r) => ({
_value: ((float(v: r._value_cycle) - float(v: r._value_reject)) / float(v: r._value_cycle)) * 100.00 }))

Float conditional logic - NO RESULT, ERROR

quality = join(tables:{reject:reject, cycle:cycle}, on:["_start"])
|> map(fn:(r) => ({
      _value: if r._value_cycle == 0 then 5 else float(v: r._value_cycle) / float(v: r._value_reject)
    }))

Hello @salvq,
The following worked for me:

from(bucket: "default")
  |> range(start: -30d)
  |> filter(fn: (r) => r._measurement == "cpu" and r._field == "usage_user" and r.cpu == "cpu-total")
  |> count()
  |>  map(fn: (r) => ({
        output:        
        if float(v:r._value) == 0.0 then 5.0 
        else float(v: r._value) / float(v: "2.0")
   }))

Thanks @Anaisdg, missing decimals…now working perfect.

1 Like