在 Titan 图形数据库中创建顶点和边的问题

Issues with Creating Vertex and Edges in Titan Graph Database

我正在尝试在 Titan 图形数据库 (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 数据库中创建唯一的 属性 值?

请帮我解决这个问题。

  1. 顶点 ID 和边 ID 由 Titan 生成和分配。如果你想有自己的标识符,你应该定义一个属性并索引它。
  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.thinkaurelius.titan.graphdb.database.management.ManagementSystem@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 modeling and also indexing for better performance 上的 Titan 文档。