Exporting and Importing Graphs with Gremlin

DSE Version: 6.0

Video

In this unit, we’ll be tdiscussing how you can import and export graphs with Gremlin IO. Gremlin IO is suitable for exporting and importing small to medium existing graphs and it’s recommended to use this in development environments.

Transcript: 



In this section, we’ll be talking all about importing and exporting graphs with Gremlin IO.

Now that we’re familiar with the Graph API, let’s talk about gremlin IO. Gremlin IO is suitable for exporting and importing small to medium existing graphs and it’s recommended to use this in development environments.

Let’s take a closer look.

Here are some of the ways you might use Gremlin IO.

Migrating between Apache Tinkerpop enabled graphs is a common use case for using Gremlin IO, as is serializing graphs between databases and tools.

You can also use Gremlin IO to make backup copies of graphs.

One again, Gremlin IO is not recommended for production use and that we may end up replacing Gremlin IO with a different API in the future.  

Here are the main times of files formats you would use for graph serialization with Gremlin IO.

GraphML is a commonly used format, reminiscent of XML. It’s accepted by a wide variety of graph tools, applications, and libraries though keep in mind that GraphML is generally a loss format as it lacks support for complex data types.

Speaking of which, it’s important to consider the compatability of features for each of these formats, for example, data type support or multi and meta property support. Failure to do so may result in errors or data loss.

GraphSON is an apache-tinkerpop originated JSON like format. It’s lossless and the text format of choice for interchanging data between Apache Tinkerpop-aware, non JVM based applications.

Lastly, Gryo is extremely efficeint, lossless, binary graph format for use on the JVM. Gryo is enabled by Kryo (with a K) which is a fast and efficient object graph serialization framework for Java. This is the prefered file format for data interchange inside the Apache Tinkerpop Stack.

Let’s put some of these formats to use. Here’s an example of using Gremlin IO with the GraphML format.

The syntax is fairly straightforward, we call the graph.io method and let it know that we’re going to be working with GraphML. Then we use the writeGraph method to export an existing graph and the readGraph method when importing a graph from a supported file.

Here’s an example of what a GraphML file looks like for the two nodes and one edge from the previous slide and as you can see, it’s a human readable format for knowledge XML and XMLSchema helps here.

Next, let’s look at using Gremlin IO with the GraphSON format. As you can see, the syntax here is nearly identical, with the exception of specifying that we’re using graphson in the graph.io method and specifying a graphson compliant file.

For additional customizations, please see the documentation.

And here’s what the GraphSON file looks like for our two vertices and one edge from the previous slide.. As you can, see it’s in JSON format and human readable.

Finally, here’s how we load a Kryo file with gryo. The syntax is similar to our other examples with the exception of changing our file format method to gryo in the graph io method.

Because Kryo is a binary format, there’s no human readable output to take a look at.

Let’s get some hands on practice with Gremlin IO.

No write up.
No Exercises.
No FAQs.
No resources.
Comments are closed.