user732456
user732456

Reputation: 2688

How to import data from any file format into JanusGraph

I want to import some data into JanusGraph.

I got the latest release from JanusGraph download. I opened up the Gremlin console and initialised the default connection from getting started tutorial.

gremlin> graph = JanusGraphFactory.open('conf/janusgraph-berkeleyje-es.properties')

So far, so good. I created a vertex, an edge and an index. So, for now I can do some basics in the console.

Now I want to import some data for testing purposes. I don't care about the file format and the data format in it. I can prepare the files.

The problem is that I can't find a good example of how to import a data file in JanusGraph.

Can anyone help with step by step instructions?

Upvotes: 4

Views: 4914

Answers (1)

stephen mallette
stephen mallette

Reputation: 46226

The Apache TinkerPop "Getting Started" Tutorial describes how to load CSV data:

http://tinkerpop.apache.org/docs/current/tutorials/getting-started/#_loading_data

The basic process simply involves writing a Groovy script and executing it in the Gremlin Console. The script needs to simply read your data in the format of your choice - CSV, JSON, XML, etc. - using a parsing library of your choosing. For CSV you might take the simple approach demonstrated in the tutorial that just uses standard Groovy classes, but for more complex CSV files you might use a library like groovycsv for example. The point here is that once you read the data you want to load, you then just write it to the Graph instance that you instantiated in your code above. You would do that with Gremlin addV() and addE() methods.

Note that developing loading scripts like this are typically meant for "smaller" amounts of data. If you need to load a graph with billions of edges of edges an approach like this will take an extremely long time. For cases like this, you would want to load data in parallel in some way (e.g. BulkLoaderVertexProgram)

Upvotes: 5

Related Questions