How to filter NaN value?

I am trying to filter NaN value in Flux resultset, but I got the error like:
response:"error cannot compile @ 13:17-13:38: unsupported binary expression float != string "
message:“Internal Server Error”
Does there any one have idea what’s the correct value to filter data.

Query Code:
import “math”
from(bucket: “kafka_signals/oneDay”)
|> range(start: 2020-02-20T00:00:00.000000000Z)
|> filter(fn: ® =>
r._measurement == “signal” and
(r[“signal.name”] == “TCU_GPS_Data_Latitude” or r[“signal.name”] == “TCU_GPS_Data_Longitude” or r[“signal.name”] == “TCU_GPS_Data_Altitude” or r[“signal.name”] == “TCU_GPS_Data_Speed”))
|> pivot(
rowKey:["_time",“vin”],
columnKey: [“signal.name”],
valueColumn: “_value”)
|> rename(columns: {TCU_GPS_Data_Longitude: “lon”})
|> rename(columns: {TCU_GPS_Data_Latitude: “lat”})
|> filter(fn: ® => r.lon != NaN)

1 Like

You will want to convert r.lon to a String first using toString(). See toString() function | Flux 0.x Documentation for information on that. Once that’s done, you can import the strings package to do the comparison. See strings package | Flux 0.x Documentation for that.

Best Regards,
dg

1 Like

@keigo840413 Building off @davidgs’ answer, rather than converting the entire r.lon column to strings for the filter predicate, you can just do it in the predicate expression, so it doesn’t actually change the column type:

// ...
  |> filter(fn: (r) => string(v: r.lon) != "NaN")
1 Like