How to import and use standard functions in a /api/v2/ query

Hey folks,

Newly started using Flux and am prototyping queries using curl and the /api/v2

It was fast work to adapt the examples in the docs to compose useful queries, however I want to perform string manipulation (which is why I stated with Flux) now and need to import functions (as shown in the docs but with no context AFAICS).

Where would I for example add this:

import "strings"

strings.split(v: "a flux of foxes", t: " ")

to a query where I want to perform string manipulation on a tag value to search:

curl -XPOST localhost:8086/api/v2/query -sS \
  -H 'Content-type:application/vnd.flux' \
  -d 'from(bucket:"epoch")
        |> range(start:-5y)
        |> filter(fn:(r) => r._measurement == "epoch_series")
        |> filter(fn: (r) => r.subject_and_start_time == "net 2021-10-27T07:30:06Z")' 

Could some please pass me the syntax for this as I have searched and not been able to find any working example is :man_shrugging:

Thanks a lot and thanks for Flux

Hello @allomorphy,
I believe you would just do:

curl -XPOST localhost:8086/api/v2/query -sS \
  -H 'Content-type:application/vnd.flux' \
  -d 'import "strings"
strings.split(v: "a flux of foxes", t: " ")
from(bucket:"epoch")
        |> range(start:-5y)
        |> filter(fn:(r) => r._measurement == "epoch_series")
        |> filter(fn: (r) => r.subject_and_start_time == "net 2021-10-27T07:30:06Z")'

What error message did you get?

Also, this might be helpful: