Importing Graphs to JanusGraph
As of September 2019, Compose will soon no longer support JanusGraph on the platform. Provisioning of new JanusGraph deployments is disabled.
Currently there is no way to directly import data from a file into your JanusGraph deployment. You can use the Gremlin I/O library to import already existing graph data from a web-accessible source. Read a tutorial on the process in the Importing Graphs into JanusGraph article from the blog.
Steps to Import a Graph
Make the graph in JanusGraph. This will be the graph that will store the data in your JanusGraph deployment.
graph=ConfiguredGraphFactory.create("airroutes");The graph name here is "airroutes" and can now be accessed at the
graphvariable.. The Gremlin I/O library is
Choose the format of the graph data. The library has 3 format options:
GraphML (graphml) - an XML-based format and will be built using
GraphSON (graphson) - a JSON-based format and will be built using
Kryo (gyro) - for use on JVM object graphs and those a built using
Make the data available on the web. If security is a concern the data can be imported from just a URL or a URL protected by authentication. The
ToInputStream.frommethod will access the URL and create a graph from the data it finds there.
....(ToInputStream.from("url", "https://github.com/where/your-data-lives"), graph)
For an example with authentication:
....(ToInputStream.from("https://github.com/where/your-data-lives","username", "password"), graph)
Use the library to import the data into JanusGraph. Putting the pieces above together with the I/O library's constructor
.reader().create(), we can finally import the graph data into the graph.
graph.io(IoCore.graphml()).reader().create().readGraph(ToInputStream.from("url", "https://github.com/where/your-data-lives"), graph);
Commit the changes to the graph database.
This example comes from a Compose blog article and a book, Kelvin Lawrence's Graph Databases, Gremlin and Tinkerpop: A Tutorial. Running the code below in either the Gremlin console or the Data Browser will create a "airroutes" graph in your deployment and then import the data from the sample data repository that accompanies the article and was created for the book.
graph=ConfiguredGraphFactory.create("airroutes"); graph.io(IoCore.graphml()).reader().create().readGraph(ToInputStream.from("url", "https://github.com/krlawrence/graph/raw/master/sample-data/air-routes.graphml"), graph); graph.tx().commit()
Still Need Help?
If this article didn't solve things, summon a human and get some help!
Updated over 3 years ago