Keep on getting int != float error in flux query below

hi

i am unable to fathom the issue in below query//
keeping on getting ther below error

** ** runtime error @10:5-16:4: reduce: type conflict: int != float** **

basically from my bucket i am selecting the fields with “Fail” in the name of field…
i convert them to float using map …

post which i want to group on time( i have all the data for 2 time stamps 15 minutes apart only) and calculate the change in the value of last time stamped to first time stamp and finally want to filter all those fields where there is more than 100 percent failure increase or aboslute incerase by 50 or more…

will appreciate the help to get me past this

thnks
rajib

from(bucket: “perfcounter4g”)

|> range(start: -30d)

|> filter(fn: (r) => r["_field"] =~/Fail/)

|> map(fn: (r) => ({ r with _value: float(v: r._value) }))

|> drop(columns: ["_start", “_stop”,“table”,"_measurement"])

|> group(columns: ["_time","_field"])

|> sum(column: “_value”)

|> group(columns: ["_field"])

|>reduce(fn: (r,accumulator) => ({

      base_value: if float(v: accumulator.base_value) > float(v: r._value) then accumulator.base_value else r._value,

      change_pcntage :  int(v: (r._value-accumulator.base_value) / accumulator.base_value),

      absolute_change : r._value-accumulator.base_value,

      }),

      identity: {base_value: 0,change_pcntage: 0,absolute_change : 0}

)

|> filter(fn:(r) => r.change_pcntage >1 and r.absolute_change >50)

The “base_value” in your identity record is a int and you said you converted your r._value into float with the map() function. The base_value is set to r._value in the else section.
Maybe a type conversion there works, or change the “base_value” from 0 (int) to 0.0 (float) so you can save float values in it.

1 Like

i changed the reduce part of the code above to

|>reduce(fn: (r,accumulator) => ({

      base_value: if float(v: accumulator.base_value) > float(v: r._value) then float(v: accumulator.base_value) else float(v: r._value),

      **change_pcntage :  float(v: (r._value-accumulator.base_value)) / float(v: accumulator.base_value),**

      absolute_change : r._value-accumulator.absolute_change,

      }),

      **identity: {base_value: 0.0,change_pcntage: 0.0,absolute_change : 0.0}**

)

and it worked// the changed portions are in bold//
though it is solved it was more like a trial and error //could not fully justify why the earllier was not working