How to overwrite vertices ID in Titan Database?

这一生的挚爱 提交于 2019-12-01 21:11:56

Very few graph databases actually allow you to set the element identifier. They all tend to have their own ID systems whether you are using Neo4j, OrientDB, Titan, etc. TinkerGraph is really the only Blueprints implementation that allows ID assignment.

If you want to keep your ID, then you should simply rename it to something else. Instead of "id", perhaps you could use "iid". To make things more transparent, from a programming perspective, you might consider use of the IdGraph wrapper, which would allow you to do something like:

gremlin> base = TitanFactory.open('/tmp/titan-berkley')
==>titangraph[local:/tmp/titan-berkley]
gremlin> g = new IdGraph(base, true, false)            
==>idgraph[titangraph[local:/tmp/titan-berkley]]
gremlin> g.addVertex(45)  
==>v[45]
gremlin> g.v(45)
==>v[45]

You can see IdGraph allows it to appear as though you are assigning the element id itself. Behind the scenes it is actually just using key indices.

@Stephen, Cant say about the gremlin terminal, but tried this through Titan Java API and it didnt work. Even after passing id's while creating vertices in the id graph, default id's were assigned to nodes.

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!