2017-02-21 83 views
0

我想將子圖導出到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"]) 

什麼問題?

回答

0

我認爲問題是你有一個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) 
+0

我使用泰坦1.0和圖形對象是使用'圖= TitanFactory.open泰坦圖(」 ../ conf/titan-cassandra.properties「)'當用上面的gremlin查詢創建子圖時,它給出'TinkerGraph'對象? 那麼我們可以創建子圖作爲泰坦圖對象嗎? –

+0

我試過你的代碼在gremlin它給mapper對象的錯誤爲'沒有這樣的屬性:TitanGraphSONModule類:groovysh_evaluate' –

+0

是的,子圖是內存中的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 –