Issue with using functions in Flux

InfluxDB1.8 CLI
I was trying to use time() function in a map function to convert a string timestamp to time.
I tried to use other type conversion functions too. The result is always the same:
[httpd] ::1 - - [07/Jul/2020:15:29:57 +0200] “POST /api/v2/query HTTP/1.1” 500 86 “-” “Go-http-client/1.1” f3039aec-c055-11ea-8001-5e90ab4dd587 9068508
2020-07-07T13:30:06.076949Z error [500] - “compile function @ 0:0-0:0: type error 0:0-0:0: undefined identifier “time”” {“log_id”: “0NrM~dp0000”, “service”: “httpd”}

I looked on examples, and the documentation, but I couldn’t figure out what could be the problem. Using a wrong named paramtere notifies me that it should be “v”. So it finds the function but I still got the above error.

Example query:
from(bucket: “db/retentionPolicy”)
|> range(start: -1d)
|> filter(fn: ® => r._measurement==“message_changes”)
|> limit(n: 5)
|> pivot(rowKey:["_time"], columnKey:["_field"], valueColumn:"_value")
|> map(fn: ®=> ({
time: r._time,
message_id: r.message_id,
user_id: r.changed_by,
expires_at: time(v: r.expires_at)

Any help/info would be appriciated!

Hello @csballa,
Welcome! Can you please share what your expires_at time column looks like? What format is the timestamp?
Any way you can share some of your input data?
Thank you.

Also please note the differences between the
time() and toTime() functions.

Hello @Anaisdg,
Thank you for the reply.
The expire_at is a utc timestamp in string format with the Z ending. The point is written with the older influx-java client:

The timestamp string example: “2020-07-06T15:53:03.967Z”

Hello @csballa,
According to the docs, time() assumes all numeric input values are nanosecond epoch timestamps.
I believe your timestamp needs to look like:


you’ll have to change the string first

|> map(fn: (r) => ({ r with expires_at: r.expires_at + "0000" }))

Thank you @Anaisdg, I missed that point, however the problem still persists. I tried other conversion functions, substring for example, and I still got the same error: ““compile function @ 0:0-0:0: type error 0:0-0:0: undefined identifier “time”” {“log_id”: “0NrM~dp0000”, “service”: “httpd”}”.
If I mistype or try to use a non existing function I got the following error in the CLI:
“Error: type error 1:349-1:352: undefined identifier “foo””
So the later error is thrown directly from the cli without appearing in the fluxd console. The former one appears on the console and in the CLI I got only the 500 unknown server error.
It looks like the cli/server somehow cannot resolve/get the proper function.