Gremlin通过java读取外部JSON顶点并添加到现有的开放图形给出无效顶点提供的异常?

时间:2017-02-13 13:19:37

标签: java json titan gremlin

我正在尝试读取外部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());

1 个答案:

答案 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]