将子图(sideeffect)导出到json文件并导入图中
问题描述:
我想将子图导出到json文件并在其他图中导入。我试过如下:将子图(sideeffect)导出到json文件并导入图中
gremlin> subGraph = g.V().has("name","john").outE("has").subgraph("subgraph").cap("subgraph").next()
==>tinkergraph[vertices:6 edges:5]
现在我有子图对象,然后我用graphson直接写入此子对象的JSON文件,如下所示:
subGraph.io(GraphSONIo.build()).writeGraph("/tmp/subgraph.json")
但我得到的错误是这样的:
(was java.lang.IllegalStateException) (through reference chain: com.thinkaurelius.titan.graphdb.relations.RelationIdentifier["inVertexId"])
什么问题?
答
我认为问题是你有一个TinkerGraph作为你的子图,但该子图包含一个Titan标识符,Graphon不知道如何本机处理。您需要将Titan序列化程序提供给GraphSON,以便它知道如何处理RelationIdentifier
。你不说你使用的是什么版本的泰坦,但我认为这种方法适用的版本,不管:
mapper = GraphSONMapper.build().
addCustomModule(TitanGraphSONModule.getInstance()).
create()
writer = GraphSONWriter.build().mapper(mapper).create()
os = new FileOutputStream("/tmp/subgraph.json")
writer.writeGraph(os, subgraph)
我使用泰坦1.0和图形对象是使用'图= TitanFactory.open泰坦图(” ../ conf/titan-cassandra.properties“)'当用上面的gremlin查询创建子图时,它给出'TinkerGraph'对象? 那么我们可以创建子图作为泰坦图对象吗? –
我试过你的代码在gremlin它给mapper对象的错误为'没有这样的属性:TitanGraphSONModule类:groovysh_evaluate' –
是的,子图是内存中的TinkerGraph,即使你的主图是泰坦。通常情况下,这通常很有意义,因为您通常不想保留子图。我不记得你是否可以在1.0版中使用Titan的子图 - 我认为这很快会作为TinkerPop的一个特性加入。至于你的错误,我想你可能需要将这个类导入到控制台 - 你可以在这里找到包名:https://github.com/thinkaurelius/titan/blob/1.0.0/titan-core/src/主/ JAVA/COM/thinkaurelius /钛/ graphdb/TinkerPop有关/ IO/graphson/TitanGraphSONModule.java –