I want to present data in a tabular manner, and don't want to type the name of every column (also they could vary from query to query, i.e. more keys in my map), as I have them as keys (either as map keys or item in a list). It is like pivot or transpose of your data.
Thanks Gary! I just used this approach and it cut my runtime by over 50% (20.3s -> 8.8s). Part of that was because your approach cut down on the amount of data being transmitted, but it's still a nice gain.
If you're curious, here's the code comparison. Note: This was run from within python.
Original, bad query
Cypher returned a tall dataset, then used df.pivot() to get the fields as their own columns.
MATCH (n:Account)
UNWIND keys(n) AS Key
WITH collect(DISTINCT Key) AS Keys
MATCH (n:Account)
UNWIND Keys AS Key
RETURN n.acct_id, Key, n[Key] AS Value
Better method using APOC fromLists
Cypher returned each record as a dict (aka, map in Neo4j), which I could then easily convert into a dataframe.
MATCH (n:Account)
UNWIND keys(n) AS Key
WITH collect(DISTINCT Key) as Keys
MATCH (n:Account)
WITH Keys, n
RETURN apoc.map.fromLists(Keys, [key in Keys | n[key]]) AS Maps