I have a table of senders and receivers:
Table A:
+------+--------+
|sender|receiver|
+------+--------+
| A| B|
| B| C|
| C| D|
| D| A|
| E| B|
| A| D|
| E| C|
+------+--------+
I want to create a graph with connections from 'sender' to 'receiver'. For example, A -(rel)-> B
The values in the sender column can also appear in the receiver column. However, I do not want the nodes A,B,C,D, and E to be repeated in my graph. They must only appear once in the final graph.
I tried doing this:
LOAD CSV WITH HEADERS FROM 'file:///graph' AS row
CREATE (:sender_node { sender: row.sender})
MATCH (n:sender_node)
WITH n.sender AS sender, collect(n) AS nodes
WHERE size(nodes) > 1
FOREACH (n in tail(nodes) | DELETE n)
LOAD CSV WITH HEADERS FROM 'file:///graph' AS row
CREATE (:receiver_node { receiver: row.receiver})
MATCH (n:receiver_node)
WITH n.receiver AS receiver, collect(n) AS nodes
WHERE size(nodes) > 1
FOREACH (n in tail(nodes) | DELETE n)
LOAD CSV WITH HEADERS FROM 'file:///graph' AS row
MATCH (from_var:sender_node {sender: row.sender}),(to_var:receiver_node {receiver:row.receiver})
CREATE (from_var)-[:rel]->(to_var)
RETURN *
I basically deleted the duplicates separately in sender and receiver nodes. But since the nodes A, B, C, and D appear in both 'sender' and 'receiver' columns, they appear twice in the graph. I want to correct this part.