Search code examples
cassandratitangremlintinkerpop3

Issues with Creating Vertex and Edges in Titan Graph Database


I am trying to create vertex and edges in Titan graph database (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]

Questions:

1) Why is the vertex number returned here are not sequence and it is some random number? For addEdge step also it is creating edge with some random value (kblqtz-kblsxk-d6vp-1oysvhk)

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

2) I want my TId value should be unique I have tried the following and got Error Msg:

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

How can I create a unique property value in Titan database?

Kindly help me to resolve this.


Solution

    1. Vertex ids and edge ids are generated and assigned by Titan. If you want to have your own identifier, you should define a property and index it.
    2. The error No such property: TId indicates that you are trying to use a variable TId that has not been initialized. You should define the vertex property before trying to index it

      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]
      

    Please refer to the Titan documentation on schema and data modeling and also indexing for better performance.