Importing Graphs to JanusGraph

🚧

JanusGraph Deprecation

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

  1. 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 graph variable.. The Gremlin I/O library is graph.io()

  2. Choose the format of the graph data. The library has 3 format options:
    GraphML (graphml) - an XML-based format and will be built using graph.io(IoCore.graphml())
    GraphSON (graphson) - a JSON-based format and will be built using graph.io(IoCore.graphson())
    Kryo (gyro) - for use on JVM object graphs and those a built using graph.io(IoCore.gryo())

  3. 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.from method will access the URL and create a graph from the data it finds there.
    For example:
    ....(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)

  4. 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);

  5. Commit the changes to the graph database. graph.tx().commit()

Full Example

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!