Array support in grafana/flux

  • Version: * v9.1.1 (9e60a1bff1)
    OS: Centos 8?

Is support for array or experimental/array removed from latest grafana?
I get below error:
500 Internal Server Error: type error 1:1-1:15: unknown import path: “array”

What am I trying to do?
– I have a table with 2 columns like (1st column is a string (with commas)):
labels value
A,B,D 10
B,D 20
C,D. 10
A,C 15

I want to show only substring of 1st column i.e. I want only say B and C, and I want total output. So, expected output will be:
labels value
B 30
C 25

So, I was trying to convert the labels column using string split function to an array, and from that array, I will pick only labels I want. Any other ways to do it?

What version of InfluxDB are you running? Also, Flux is packaged with InfluxDB, so when you upgrade InfluxDB, you should get a newer version of Flux.

Can you confirm your Flux query works fine in Influx Data Explorer?

It gives same error in Explorer:

I am running influxdb 1.8. I know it’s not latest, but upgrade has some constraints.
I thought flux was directly built in latest versions of Grafana (and it’s not dependent on influxdb)
So, is it because of influxdb version ?

Earlier, I remember installing separate docker images for flux, influxdb and grafana. But now, even though I didn’t install flux separately, I was getting Flux option in InfluxDB datasource in grafana. So, I thought it’s something provided by Grafana now.

(and thank you are looking)

Between, I solved my issue in a different way, but it would be good if I could get “array” also working. It will be easier to format using “array” functions I believe.

|> map(
        fn: (r) => ({_value: r._value, 
              if (strings.containsStr(v: r.labels, substr: "B")) then "B"
              else if (strings.containsStr(v: r.labels, substr: "C")) then "C"
              else r.labels}),

Glad you got it resolved another way, but just to be clear, the screenshot you provided is from Grafana, not Influx Data Explorer. Influx Data Explorer looks like this and is accessed usually via http://ip-address:8086

1 Like

oh okay. It gives 404 for me. Maybe I need to enable something in influxdb config.
But I tried directly running on influx cli:

> import "strings"
> import "array"
Error: type error 1:1-1:15: unknown import path: "array"

And I see same error. So, it does look like maybe it’s bound to influxdb version rather than Grafana. I will probably try it in some test setup and see, and maybe will plan upgrade of production DB then.
Thank you very much for your help.

import "experimental/array"
import "strings"

array.from(rows: [{value: "A,B"}])
  |> map(fn: (r) => {
    parts = strings.split(v: r.value, t: ",")
    return {first: parts[0], second: parts[1]}
1 Like