我正在尝试读取外部JSON顶点并将其添加到退出的开放titan图形中。如下:
gremlin> newVertex = graph.io(GraphSONIo.build()).reader().create().readVertex(new FileInputStream("/tmp/sample_vertex.json"),null);
gremlin> v[42092]
gremlin> existingVertex = graph.V(4145).next();
gremlin> v[4145]
gremlin> existingVertex.addEdge("has",newVertex);
Invalid vertex provided: v[42092]
我已经使用GraphSON.io导出了顶点,如下所示:
gremlin> graph.io(GraphSONIo.build()).writer().create().writeVertex(new FileInputStream("/tmp/sample_vertex.json"),g.V().next());
答案 0 :(得分:1)
readVertex
的签名如下所示:
Vertex readVertex(InputStream inputStream, Function<Attachable<Vertex>, Vertex> vertexAttachMethod)
如果您向null
提供了vertexAttachMethod
,则不会尝试将顶点附加到您的图表中,而您只是获得一个未附加的StarVertex
作为结果。请考虑这种方法:
gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> start = graph.io(GraphSONIo.build()).reader().create().readVertex(new FileInputStream('v.json'), Attachable.Method.create(graph))
==>v[1]
gremlin> gremlin> g.V(start).as('start').
......1> addV().as('end').
......2> addE('has').from('start').to('end')
==>e[1][1-has->0]