JanusGraph output substrate as GraphSON error

I am trying to output a subgraph as GraphSON in Gremlin wrapper using JanusGraph.

TinkerPop documentation for reference: http://tinkerpop.apache.org/docs/current/reference/#graphson-reader-writer

When I write the complete graph it works great, however, when I want to write the subgraph I requested using the following commands:

gremlin> subGraph = g.V(45240).repeat(__.bothE().subgraph('subGraph').bothV()).times(4).cap('subGraph').next()

      

I am using the same write command:

gremlin> subGraph.io(IoCore.graphson()).writeGraph("45240_sub4.json")

      

I am getting this error:

(was java.lang.IllegalStateException) (via link chain: org.janusgraph.graphdb.relations.RelationIdentifier ["inVertexId"])

Searching around, I found another thread that said I need to import the package to do this correctly (for TitanGraph, but I figured this would apply to JanusGraph as well): Package import in gremlin

However, when I try to import:

gremlin>  import com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule

      

I am getting this error:

Invalid import definition: 'com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule'; reason: failed to start: script1494618250861805544050.groovy: 1: cannot resolve class com.thinkaurelius.titan.graphdb.tinkerpop.io.graphson.TitanGraphSONModule @ line 1, column 1.import com.thinkaurelius.titan.graphdb.tinkerpop. graphson.TitanGraphSONModule ^

1 error

How can I output subgraph as GraphSON in Gremlin wrapper using JanusGraph?

+3


source to share


2 answers


When you use a step subgraph()

, the result is TinkerGraph

, however, its vertex and boundary IDs carry over from the instance JanusGraph

. In particular, edge ids are of the type RelationIdentifier

for which the custom JanusGraph serializer JanusGraphSONModule

should export cleanly.

Here's an example based on 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')

      

+3


source


You probably just need to import the JanusGraph equivalent of this Titan module, which should be: org.janusgraph.graphdb.tinkerpop.io.graphson.JanusGraphSONModule

So this import should work:



gremlin>  import org.janusgraph.graphdb.tinkerpop.io.graphson.JanusGraphSONModule

      

+1


source







All Articles