How to overwrite vertices ID in Titan Database?

后端 未结 2 920
梦如初夏
梦如初夏 2021-01-20 17:08

I\'m using a framework that generates objects Node and they already have assigned a id. Now they need to be converted to Titan vertices with the same ID control

相关标签:
2条回答
  • 2021-01-20 17:42

    @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.

    0 讨论(0)
  • 2021-01-20 17:44

    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.

    0 讨论(0)
提交回复
热议问题