mercury019
mercury019

Reputation: 43

create a neo4j graph from a csv file containing three columns

I have a csv file containing producers and consumers of some topics. e.g

producer,topic,consumer
PRODUCER-1,TOPIC-A,CONSUMER-1
PRODUCER-2,TOPIC-B,CONSUMER-2
PRODUCER-1,TOPIC-C,CONSUMER-3
PRODUCER-1,TOPIC-D,CONSUMER-1
PRODUCER-2,TOPIC-E,CONSUMER-3

I am trying to plot a graph using neo4j in Zeppelin notebook to achieve this. I managed to load the csv as shown below but couldn't get the pubsub graph showing the relationship between the producers and consumers via the topics working.

LOAD CSV FROM 'file:///data/pubsub.csv' AS row
WITH row[0] AS Producer, row[1] AS Topic, row[2] AS Consumer
RETURN Producer, Topic, Consumer

Would appreciate any help please. Thanks in advance

Upvotes: 2

Views: 217

Answers (1)

Tomaž Bratanič
Tomaž Bratanič

Reputation: 6514

Try to first store the dataset into Neo4j and then query it... This will help you with Zeppelin visualizations

LOAD CSV WITH HEADERS FROM 'file:///data/pubsub.csv' AS row
MERGE (p:Producer{id:row.producer})
MERGE (t:Topic{id:row.topic})
MERGE (c:Consumer{id:row.consumer})
MERGE (p)-[:PRODUCER]->(t)
MERGE (t)-[:CONSUMER]->(c)

Now that you have saved your data into graph, you can try and query it in Zeppelin with:

MATCH p=()-->()
RETURN p

Upvotes: 3

Related Questions