Skip to content

Instantly share code, notes, and snippets.

@bahreex
Created September 15, 2018 20:40
Show Gist options
  • Save bahreex/2645820a084d951786635f66b34ac6a4 to your computer and use it in GitHub Desktop.
Save bahreex/2645820a084d951786635f66b34ac6a4 to your computer and use it in GitHub Desktop.
//Create Unique Conversation nodes. They cannot be duplicate in a graph since they can each contain many mail messages
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/bahreex/7f7074b16db942c7c36afdfcca719d32/raw/fcdafdadfe03012c91f8842977563535109125dd/msgx.csv" AS row
MERGE (:Conversation {convid: row.ConversationID});
//Create Unique Message nodes. They cannot be duplicates in a graph
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/bahreex/7f7074b16db942c7c36afdfcca719d32/raw/fcdafdadfe03012c91f8842977563535109125dd/msgx.csv" AS row
MERGE (:Message {msgid: row.MessageID, subject: row.Subject, recipient: row.Recipient, send_date: row.SendTime});
//Create Unique Sender nodes. They cannot be duplicates in a graph
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/bahreex/7f7074b16db942c7c36afdfcca719d32/raw/fcdafdadfe03012c91f8842977563535109125dd/msgx.csv" AS row
MERGE (:Sender {mailid: row.Sender});
CREATE INDEX ON :Conversation(convid);
CREATE INDEX ON :Message(msgid);
CREATE INDEX ON :Sender(mailid);
CREATE CONSTRAINT ON (co:Conversation) ASSERT co.Conversation IS UNIQUE;
CREATE CONSTRAINT ON (ms:Message) ASSERT ms.Message IS UNIQUE;
CREATE CONSTRAINT ON (sd:Sender) ASSERT sd.Sender IS UNIQUE;
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/bahreex/7f7074b16db942c7c36afdfcca719d32/raw/fcdafdadfe03012c91f8842977563535109125dd/msgx.csv" AS row
MATCH (con:Conversation {convid: row.ConversationID})
MATCH (msg:Message {msgid: row.MessageID})
MERGE (con)-[:CONTAINS_MESSAGE]->(msg);
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/bahreex/7f7074b16db942c7c36afdfcca719d32/raw/fcdafdadfe03012c91f8842977563535109125dd/msgx.csv" AS row
MATCH (con:Conversation {convid: row.ConversationID})
MATCH (msg:Message {msgid: row.MessageID})
MERGE (con)<-[:CONTAINED_IN_CONVERSATION]-(msg);
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/bahreex/7f7074b16db942c7c36afdfcca719d32/raw/fcdafdadfe03012c91f8842977563535109125dd/msgx.csv" AS row
MATCH (msg:Message {msgid: row.MessageID})
MATCH (snd:Sender {mailid: row.Sender})
MERGE (msg)-[:MESSAGE_HAS_SENDER]->(snd);
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/bahreex/7f7074b16db942c7c36afdfcca719d32/raw/fcdafdadfe03012c91f8842977563535109125dd/msgx.csv" AS row
MATCH (msg:Message {msgid: row.MessageID})
MATCH (sndr:Sender {mailid: row.Sender})
MERGE (sndr)-[:IS_SENDER_IN_MESSAGE]->(msg);
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/bahreex/7f7074b16db942c7c36afdfcca719d32/raw/fcdafdadfe03012c91f8842977563535109125dd/msgx.csv" AS row
MATCH (con:Conversation {convid: row.ConversationID})
MATCH (sndr:Sender {mailid: row.Sender})
MERGE (sndr)-[:IS_SENDER_IN_CONVERSATION]->(con);
USING PERIODIC COMMIT
LOAD CSV WITH HEADERS FROM "https://gist.githubusercontent.com/bahreex/7f7074b16db942c7c36afdfcca719d32/raw/fcdafdadfe03012c91f8842977563535109125dd/msgx.csv" AS row
MATCH (con:Conversation {convid: row.ConversationID})
MATCH (sndr:Sender {mailid: row.Sender})
MERGE (sndr)<-[:CONVERSATION_HAS_SENDER]-(con);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment