I query data from InfluxDB 2 using Flux query like:
from(bucket: "first")
|> range(start: time(v: 0))
|> filter(fn: (r) => r["_measurement"] == "test" and r._field == "volume")
|> keep(columns: ["_time", "_value"])
|> last()
This gives me a correct result, but it gives me the _time
column as a human-readable date.
I need a timestamp instead. Seconds, milliseconds, nanoseconds, doesn't matter.
I tried adding |> map(fn: (r) => ({ r with timestamp: uint(v: r._time) }))
before keep(...
and modifying keep(...
to keep the new field. And this still works correctly, but it significantly increases the response time (and this is understandable, why).
I'm pretty sure that I'm doing this wrong, so how do I do this?
updated: I managed not to increase the response time. I moved |> map
below last()
, but I still think this is not the best way of doing this.