Batch import cvs into graph

49 views
Skip to first unread message

CasperCLD

unread,
Feb 20, 2015, 4:32:13 AM2/20/15
to orient-...@googlegroups.com
Hi!
I've been searching in OrientDB's documentation and could not find how to properly import a cvs file containing nodes and edges.
The csv file looks like this:
user_id,user_profile_id
1,2
1,53
1,52
1,62

Where a user_id has made an edit to a user_profile_id.
I have the following code: 
final OrientGraphFactory factory = new OrientGraphFactory(
"plocal:" + DB_DIR, "user", "************");

System.
out.println(factory.exists());
assert(!factory.exists());


OrientGraph graph = factory.getTx();
graph.getRawGraph().declareIntent(
new OIntentMassiveInsert() );


BufferedReader br =
new BufferedReader(new FileReader(dataset.csv));
String line;
int c = 0;
while ((line = br.readLine()) != null) {
String[] vertexes = line.split(
",");
vertexes[
1] = vertexes[1].replace("\r\n","");
Vertex v1 = graph.addVertex(vertexes[
0]);
v1.setProperty(
"user_id", vertexes[0]);
Vertex v2 = graph.addVertex(vertexes[
1]);
v2.setProperty(
"user_profile_id", vertexes[1]);
graph.addEdge(
null,v1,v2, "edits");

if(++c%100000==0) {
System.
out.println("Added "+ c + " edges");
graph.commit();
}


}
br.close();

My problem is that the vertexes are not unique (e.g. user_id '1' is added multiple times). Is there a way to make sure that the vertex only gets created when the vertex does not exist?

Alexej Bondarenko

unread,
Feb 22, 2015, 6:10:49 AM2/22/15
to orient-...@googlegroups.com

CasperCLD

unread,
Feb 23, 2015, 3:05:08 AM2/23/15
to orient-...@googlegroups.com
Hi Alexej,

Yes, but I don't understand how to import relations between two vertexes when they're already inserted. In the example there are two classes and 1 relation. While in my example, there is 1 class and 1 relationship. Between the one class there are multiple relations. 
In my case: a user_id edits another user's profile page.  (http://snap.stanford.edu/data/wiki-Talk.html)
Can you help me out?

Casper
Reply all
Reply to author
Forward
0 new messages