Create dictionary from table

array.from() creates a table from a list of records. Does anyone know of a way I can do the opposite and construct a list of records from a table? I’d like to then use dict.fromList to create a dictionary from that list of records, but I can’t find a way to make it work.

Let’s assume I have some table that is formatted such:

lookupTable = someOtherTable
|> map(fn: ® => ({r with
key: r.name,
value: r.color
}))
|> keep(columns: [“key”, “value”])

so, now I’d like to do this:

lookupDict = dict.fromList(pairs: lookupTable)

so that I can write a function like this:

findColor = (n) => dict.get( dict: lookupDict , key: n, default: “” )

The idea here is to be able to use this dictionary lookup rather than a join which takes an incredibly unfortunate huge amount of time.

This fails though at the dict.fromList with:

 error calling function "fromList" @34:19-34:71: keyword argument "pairs" should be of an array of type object, but got an array of type [t5751]

Thanks for any suggestions.

Brian

Thanks @bknoth. This currently isn’t possible, but I’ve created a related issue in the Flux repo:

Extract a table as a usable array · Issue #3424 · influxdata/flux · GitHub.

1 Like

@scott , thank you. I think the example you show in the ticket is precisely what we need.

1 Like