flux icon indicating copy to clipboard operation
flux copied to clipboard

Cannot index a returned array while inside map.

Open ewendai opened this issue 6 years ago • 4 comments
trafficstars

data |> map(fn: (r) => ({_value: strings.split(v: r._value, t: "")[0]})) returns Error: cannot compile polymorphic function: type variable "t79" is not monomorphic

strings.split(v: "hai", t: "") works perfectly fine and returns [h, a, i]

strings.split(v: "hai", t: "")[1] works perfectly fine and returns a

ewendai avatar Jun 18 '19 16:06 ewendai

I see this is quite an old bug but is anyone aware of any solution or workaround to this? I have two measurements, one is tagged with the human-readable last 5 digits of a serialnumber and the other is tagged with the full serialnumber. I'm preparing to use them both in a join by using;

map(fn: (r) => ({ r with suffix: strings.sub(v: r.serialnumber, start: -5, end: -1) }))

but getting

cannot compile polymorphic function: type variable \\"t78\\" is not monomorphic"

andhya avatar Jun 13 '23 18:06 andhya

@andhya Try this:

// ...
    |> map(
        fn: (r) => {
            length = strings.strlen(v: r.serialnumber)
            suffix = strings.substring(v: r.serialnumber, start: length - 5, end: length)

            return {r with suffix: suffix}
        },
    )

sanderson avatar Jun 13 '23 19:06 sanderson

Thanks @sanderson , unfortunately that gives a subtly different but similar error; cannot compile polymorphic function: type variable \\"t94\\" is not monomorphic

andhya avatar Jun 14 '23 10:06 andhya

even with the following;

      |> map(
              fn: (r) => {
                   serialnumber = ""AH20230614""
                   suffix = strings.substring(v: serialnumber,start:1,end:3)
                   return {r with machine_id: suffix}
                   },
              )

I get;

cannot compile polymorphic function @ 10:15-14:14: type variable \\"t81\\" is not monomorphic

andhya avatar Jun 14 '23 11:06 andhya

This issue has had no recent activity and will be closed soon.

github-actions[bot] avatar Jul 16 '24 01:07 github-actions[bot]