-1
LOAD CSV WITH HEADERS FROM 'http://127.0.0.1/static/relations/252.csv' AS line  
MATCH (a:ip{value:line.userIp}),(b:email{value:line.ucEmail})  
MERGE (a)-[rel:mayrelations]->(b)  
WITH rel, COALESCE(rel.spendTime, []) + line.spendTime AS spendTime
UNWIND spendTime as r0
WITH rel, collect(distinct r0) AS unique
set rel.spendTime= unique  


WITH rel, COALESCE(rel.eventOccurTime, []) + line.eventOccurTime AS eventOccurTime
UNWIND eventOccurTime as r1
WITH rel, collect(distinct r1) AS unique
set rel.eventOccurTime= unique

This syntax does not work, and raises the error: "Variable line not defined", I believe this means 'line' variable can be used only once. How can I use it twice?

Tomaž Bratanič
  • 6,319
  • 2
  • 18
  • 31
Li Eric
  • 19
  • 5
  • Does this answer your question? [What with clause do? Neo4j](https://stackoverflow.com/questions/30699236/what-with-clause-do-neo4j) – The Grand J Sep 08 '20 at 03:49

1 Answers1

0

You have to add the line variable to the WITH statements: If you check the official docs you can see the following instructions:

It is important to note that WITH affects variables in scope. Any variables not included in the WITH clause are not carried over to the rest of the query.

LOAD CSV WITH HEADERS FROM 'http://127.0.0.1/static/relations/252.csv' AS line
MATCH (a:ip{value:line.userIp}),(b:email{value:line.ucEmail})
MERGE (a)-[rel:mayrelations]->(b)
WITH line, rel, COALESCE(rel.spendTime, []) + line.spendTime AS spendTime UNWIND spendTime as r0 WITH line, rel, collect(distinct r0) AS unique set rel.spendTime= unique

WITH rel, COALESCE(rel.eventOccurTime, []) + line.eventOccurTime AS eventOccurTime UNWIND eventOccurTime as r1 WITH rel, collect(distinct r1) AS unique set rel.eventOccurTime= unique

Tomaž Bratanič
  • 6,319
  • 2
  • 18
  • 31