Neo4j: Allow REDUCE to work with maps

Created on 22 Aug 2016  Â·  4Comments  Â·  Source: neo4j/neo4j

I would like Cypher REDUCE to work with a map as an accumulator. As input I have a list of tuples (key,value) which I want to convert into a map.

Something like this:
REDUCE(map={}, row IN coll | SET map[row.key]=row.value)

cypher feature team-clg

Most helpful comment

I'd prefer

REDUCE(map={}, row IN coll | map + { (row.key) : row.value})

Am 22.08.2016 um 10:36 schrieb Rickard Öberg [email protected]:

I would like Cypher REDUCE to work with a map as an accumulator. As input I have a list of tuples (key,value) which I want to convert into a map.

Something like this:
REDUCE(map={}, row IN coll | SET map[row.key]=row.value)

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

All 4 comments

I'd prefer

REDUCE(map={}, row IN coll | map + { (row.key) : row.value})

Am 22.08.2016 um 10:36 schrieb Rickard Öberg [email protected]:

I would like Cypher REDUCE to work with a map as an accumulator. As input I have a list of tuples (key,value) which I want to convert into a map.

Something like this:
REDUCE(map={}, row IN coll | SET map[row.key]=row.value)

—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub, or mute the thread.

any updates on this issue?

apoc helps these days:

with [{a:1, x:'y'}, {b:2, y:'z'}] as coll
return reduce(acc={}, x in coll | apoc.map.merge(acc, x))

Reduce works with any accumulator, what is missing from Cypher is a way to to merge maps. For this I refer to this feature request: https://github.com/neo4j/neo4j/issues/4470

But, since APOC already provides such functions:

apoc.map.merge(base, patch)
apoc.map.updateTree(tree, key, value)

we currently don't consider adding these functions into Neo4j.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

mammadalipour picture mammadalipour  Â·  3Comments

LWprogramming picture LWprogramming  Â·  4Comments

lassewesth picture lassewesth  Â·  5Comments

szarnyasg picture szarnyasg  Â·  3Comments

cybersam picture cybersam  Â·  3Comments