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
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 (s:SMA)-[:ASSOCIATED_WITH]->(d:DataSet)
MATCH path = (d)-[:LINEAGE*]->(d1:DataSet)
MATCH (d1)<-[:ASSOCIATED_WITH]-(s1:SMA)
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
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?
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