Hi all! I’m trying to use a string column (named InvStatus) in a map function to output an integer as a new column (called pcsavailability). I then need to do an aggregate window on the new pcsavailability column. Problem is, because InvStatus is a string, i can’t aggregate. Is there a work around for this? Thank you!
THIS WORKS:
> from(bucket: "rt-data")
> |> range(start: v.timeRangeStart, stop: v.timeRangeStop)
> |> filter(fn: (r) => r["_measurement"] == "unit")
> |> filter(fn: (r) => r["point_name"] == "InvStatus")
> |> group(columns: ["_measurement"], mode: "by")
> |> pivot(rowKey: ["_time"], columnKey: ["point_name"], valueColumn: "_value")
> |> map(fn: (r) => ({ r with pcsavailability: if r.InvStatus == "RunPQ" then 1.0 else 0.0}))
THIS ERRORS OUT WITH : panic: column pcsavailability:float is not of type string
from(bucket: "rt-data")
|> range(start: v.timeRangeStart, stop: v.timeRangeStop)
|> filter(fn: (r) => r["_measurement"] == "unit")
|> filter(fn: (r) => r["point_name"] == "InvStatus")
|> group(columns: ["_measurement"], mode: "by")
|> pivot(rowKey: ["_time"], columnKey: ["point_name"], valueColumn: "_value")
|> map(fn: (r) => ({ r with pcsavailability: if r.InvStatus == "RunPQ" then 1.0 else 0.0}))
|> set(key: "pcsavailability", value: "_value")
|> aggregateWindow(every: 1d, fn: mean)