How to collect properties from variable length relationship inside a pattern?

I have a query that matches a pattern with multiple relationships and node types. Within that pattern one relationship is of variable length and has a property which contains a list of values. How do I collect that list in my query. I'm trying -

match (s:SMA)-[r:ASSOCIATED_WITH]->(d:DataSet)-[r1:LINEAGE*]->(d1:DataSet)<-[r2:ASSOCIATED_WITH]-(s1:SMA)
with s,s1, count(*) as count, unwind r1 as rel
with s,s1,count, collect(distinct(rel.relationKeys)) as relationKeys
merge (s)-[r3:CONNECTED_TO]->(s1)
set r3.count=count
set r3.relationKeys=relationKeys

But I gt the error -

Thank you.

It is syntax error .
I do not think you can have With x,y, unwind a as k.

unwind is to take each element of the given list

UNWIND is its own clause, you cannot embed that within a WITH clause.

Using a variable on the var-length relationship part of the pattern is deprecated. You might consider breaking the pattern down into parts, isolating the var-length part and using a path variable on that:

MATCH path = (d)-[:LINEAGE*]->(d1:DataSet)
UNWIND relationships(path) as rel
WITH s, s1, count(*) as count, collect(distinct(rel.relationKeys)) as relationKeys
MERGE (s)-[r3:CONNECTED_TO]->(s1)
SET r3.count=count
SET r3.relationKeys=relationKeys

I get the following error-

and I think I know why his is happening. Because rel.relationKeys itself is a list. So in this it's trying to collect a list into a list. Could that be why?

Okay nevermind. This worked-

match (s:SMA)-[r:ASSOCIATED_WITH]->(d:DataSet)-[r1:LINEAGE*]->(d1:DataSet)<-[r2:ASSOCIATED_WITH]-(s1:SMA)
unwind r1 as rel
unwind rel.relationKeys as rKeys
with s,s1, count(*) as count, rKeys
with s,s1,count, collect(rKeys) as relationKeys
merge (s)-[r3:CONNECTED_TO]->(s1)
set r3.count=count
set r3.relationKeys=relationKeys
1 Like