如何覆盖Titan数据库中的顶点ID? [英] How to overwrite vertices ID in Titan Database?

查看:97
本文介绍了如何覆盖Titan数据库中的顶点ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用一个生成对象Node的框架,并且它们已经分配了一个ID.现在,需要将它们转换为在框架中具有相同ID的Titan顶点(通过node.id访问)

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 controlled in the framework (accessed with node.id)

public long addNode(Node node) {    
   TitanVertex vertex = (TitanVertex) g.addVertex(null);
   g.commit();

   vertex.setProperty(ID, node.id);
   vertex.setProperty(TYPE, node.type);
   vertex.setProperty(VERSION, node.version);
   vertex.setProperty(TIME, node.time);
   vertex.setProperty(DATA, node.data);
   ...

错误:

java.lang.IllegalArgumentException: Name is reserved: id

但似乎不允许这样做.我是否应该使用一些伪造的资产来模仿次要ID?泰坦有办法做到这一点吗?

But it seems to not allow it. Should I use some fake property to imitate a secondary Id? Does Titan has some way to do that?

谢谢!

推荐答案

实际上很少有图形数据库允许您设置元素标识符.无论您使用的是Neo4j,OrientDB,Titan等,它们都倾向于拥有自己的ID系统.TinkerGraph实际上是唯一允许ID分配的Blueprints实现.

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.

如果要保留ID,则只需将其重命名为其他名称即可.代替"id",也许您可​​以使用"iid".为了使事情更透明,从编程的角度来看,您可以考虑使用 IdGraph 包装器,它可以让您执行以下操作:

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]

您可以看到IdGraph允许它看起来像您在分配元素ID本身一样.在后台,它实际上只是使用关键索引.

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.

这篇关于如何覆盖Titan数据库中的顶点ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆