Java – janusgraph outputs the subgraph as a graphson error
I tried to use janusgraph to output a sub graph in the gremlin shell as graphson
Tinkerpop documentation for reference: http://tinkerpop.apache.org/docs/current/reference/#graphson -reader-writer
This works when I write a complete graph, but when I want to write a subgraph that I query with 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 received this error:
Searching around, I found another thread saying that I need to import a package to perform this operation correctly (for titangraph, but I think it also applies to janusgraph): import package in gremlin
However, whenever I try to import:
gremlin> import com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule
I received this error:
How do I use janusgraph to output a subgraph as graphson in the gremlin shell?
Solution
When you use the subgraph () step, the result is tinkergraph, but its vertex and edge IDs are inherited from the janusgraph instance In particular, the type of edge ID is relationidentifier, which requires janusgraph's custom serializer janusgraphsonmodule to export cleanly
This is an example based on Titan previous example. You can run it 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')