Example Code(JAVA):
Cluster cluster = Cluster.open(yml.getFile());
DriverRemoteConnection driver = DriverRemoteConnection.using(cluster, "graph_traversal");
GraphTraversalSource allGraph = AnonymousTraversalSource.traversal().withRemote(driver);
// Using Io --> generate a file in server-side
allGraph.Io("File.json").write().iterate()
// Using GraphSONWriter
GraphSONMapper mapper = GraphSONMapper.build().addRegistry(JanusGraphIoRegistry.instance()).version(GraphSONVersion.V3_0).create();
GraphSONWriter writer = GraphSONWriter.build().mapper(mapper).create();
ByteArrayOutputStream output = new ByteArrayOutputStream();
// output --> "" (Empty)
writer.writeGraph(output, allGraph.getGraph());
// output --> "~" (Only Vertex Ids)
writer.writeVertices(output, allGraph.V());
I'm trying to export a Graph as GraphSON with remote server. But IO step doesn't provide a functionality for remote-export. With GraphSonWriter, It doesn't write the contents properly. How can I export a graph in GraphSON format with remote-server environment?
Thank you.
Until TinkerPop provides better support around the g.io()
step for remote environments, it still only works well for reading and writing local to where the Gremlin execution occurs. If you want to export a graph to GraphSON at a remote source then there are a few options depending on the graph you are using. You tagged this question with JanusGraph so I'll focus on that. You could:
GraphSONWriter
on the server and then provide writeGraph()
an OutputStream
that will write to a byte[]
or String
and then return that to your client. g.E().subgraph('sg').cap('sg')
and copy the whole graph to a subgraph. That will yield you a TinkerGraph
on the client and from there you can use io()
as you like to write the graph locally to GraphSON. This only works if you are using Java as other languages don't yet support subgraph()
well.JanusGraph
instance and then io()
will work as normal.