I am trying to output a subgraph as GraphSON in the Gremlin shell with JanusGraph.
TinkerPop documentation for reference: http://tinkerpop.apache.org/docs/current/reference/#graphson-reader-writer
When I write the full graph this works fine, however, when I want to write a subgraph that I've queried using these commands:
gremlin> subGraph = g.V(45240).repeat(__.bothE().subgraph('subGraph').bothV()).times(4).cap('subGraph').next()
I use the same write command:
gremlin> subGraph.io(IoCore.graphson()).writeGraph("45240_sub4.json")
I get this error:
(was java.lang.IllegalStateException) (through reference chain: org.janusgraph.graphdb.relations.RelationIdentifier["inVertexId"])
Searching around, I found another thread that said I needed to import a package in order to do this properly (for TitanGraph, but I figured it would apply to JanusGraph as well): Import package in gremlin
However, whenever I try to import:
gremlin> import com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule
I get this error:
Invalid import definition: 'com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule'; reason: startup failed: script1494618250861805544050.groovy: 1: unable to resolve class com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule @ line 1, column 1. import com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule ^
1 error
How can I output a subgraph as a GraphSON in Gremlin shell using JanusGraph?
When you use the subgraph()
step, the result is a TinkerGraph
, however its vertex and edge IDs are carried over from the JanusGraph
instance. In particular, the edge IDs are of type RelationIdentifier
which require JanusGraph's custom serializer JanusGraphSONModule
to export cleanly.
Here is an example, based off a previous example from Titan, that you can run in the Gremlin Console:
graph = JanusGraphFactory.open('inmemory')
graph.io(graphson()).readGraph('data/tinkerpop-modern.json')
g = graph.traversal()
subGraph = g.E().hasLabel('knows').subgraph('sg').cap('sg').next()
graphsonIO = IoCore.graphson().graph(subGraph).registry(JanusGraphIoRegistry.getInstance()).create()
graphsonIO.writeGraph('/tmp/subgraph.json')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With