2017-03-02 96 views
2

我想創建頂點和泰坦圖形數據庫的邊緣(Titan1.0.0)創建頂點和邊..問題與泰坦圖形數據庫

gremlin> graph = TitanFactory.open('titan-1.0.0-hadoop1/conf/titan-cassandra-es.properties') 

gremlin> t1 = graph.addVertex(label, "Testbed", "Name", "testbed1","Status","A","TId",101) 
==>v[1228816568] 

gremlin> r2= graph.addVertex(label, "Router", "RStatus","F","RId",1002, "TId", 101) 
==>v[3686424680] 

gremlin> t1.addEdge("tbConRtr", r2) 
==>e[kblqtz-kblsxk-d6vp-1oysvhk][1228816568-tbConRtr->3686424680] 

問題:

1)爲什麼這裏返回的頂點數是不是序列,它是一些隨機數?對於addEdge步也被一些隨機值(kblqtz-kblsxk-d6vp-1oysvhk

e[kblqtz-kblsxk-d6vp-1oysvhk][1228816568-tbConRtr->3686424680] 

2)我想創建邊緣我TId值應該是唯一的 我曾嘗試以下,並得到錯誤信息:

gremlin> mgmt.buildIndex("TId",Vertex.class).addKey(TId).unique().buildCompositeIndex(); 
No such property: TId for class: groovysh_evaluate 

我如何在Titan數據庫中創建獨特的屬性值?

請幫我解決這個問題。

回答

3
  1. 頂點標識和邊緣標識由泰坦生成和分配。如果你想擁有自己的標識符,你應該定義一個屬性並對其進行索引。
  2. 錯誤No such property: TId表示您正嘗試使用尚未初始化的變量TId。試圖索引之前,您應該定義頂點屬性它

    gremlin> graph = TitanFactory.open('conf/titan-cassandra-es.properties') 
    ==>standardtitangraph[cassandrathrift:[127.0.0.1]] 
    gremlin> mgmt = graph.openManagement() 
    ==>com.t[email protected]4b97b3d2 
    gremlin> TId = mgmt.makePropertyKey("TId").dataType(Integer.class).cardinality(Cardinality.SINGLE).make() 
    ==>TId 
    gremlin> mgmt.buildIndex("TId",Vertex.class).addKey(TId).unique().buildCompositeIndex() 
    ==>TId 
    gremlin> mgmt.commit() 
    ==>null 
    gremlin> t1 = graph.addVertex(label, "Testbed", "Name", "testbed1","Status","A","TId",101) 
    ==>v[4200] 
    gremlin> r2= graph.addVertex(label, "Router", "RStatus","F","RId",1002, "TId", 101) 
    Adding this property for key [TId] and value [101] violates a uniqueness constraint [TId] 
    

請參閱泰坦文檔上schema and data modelingindexing for better performance