如何在Gremlin中将UUID用作ID? [英] How to use a UUID as id in Gremlin?

查看:87
本文介绍了如何在Gremlin中将UUID用作ID?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要添加这样的顶点:

g.addV("foobar").property("id",1).property(... etc ...

如何设置带有uuid而不是整数ID的属性?

How can I set a property with a uuid instead of an integer id?

推荐答案

"id"可以有多种含义.如果只是说要使用UUID作为唯一标识符来查找顶点,那么将其与所选图形数据库的基础索引功能结合使用时,可以采用所采用的方法.换句话说,只要您在"id"上有一个索引,就可以快速找到顶点.在这种用法中,显然"id"实际上只是顶点的一个属性,对于某些图形数据库,您可能会发现"id"实际上是保留术语,不能用作属性键.最好选择一个不同的键名.

An "id" can have multiple meanings. If you simply mean that you want to use a UUID as a unique identifier to lookup your vertices then taking the approach you have is fine, when used in conjunction with the underlying indexing functionality of your chosen graph database. In other words, as long as you have an index on "id" then you will quickly find your vertex. In this sort of usage, "id" is really just a property of the vertex obviously and you may find that for certain graph databases that "id" is actually a reserved term and can't be used as a property key. It is likely best to choose a different key name.

如果不是使用"id"作为属性键,则表示您希望设置由 T.id 引用的实际顶点标识符,如下所示:

If instead of using "id" as a property key, you mean that you wish to set the actual vertex identifier, referred to by T.id, as in:

g.addV(T.id, uuid)

然后,您首先需要使用允许分配标识符的图形数据库实现.TinkerGraph就是这样一种实现.这样,您就可以自然地分配顶点的标识符,而不是允许图形数据库为您创建它.

then you first need to use a graph database implementation that allows the assignment of identifiers. TinkerGraph is one such implementation. In this way, you natively assign the identifier of the vertex rather than allowing the graph database to create it for you.

gremlin> graph = TinkerGraph.open()
==>tinkergraph[vertices:0 edges:0]
gremlin> g = graph.traversal()
==>graphtraversalsource[tinkergraph[vertices:0 edges:0], standard]
gremlin> g.addV(id, UUID.randomUUID())
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]
gremlin> g.V(UUID.fromString("c2d673de-2425-4b42-bc1e-68ff20e3b0a8"))
==>v[c2d673de-2425-4b42-bc1e-68ff20e3b0a8]

这篇关于如何在Gremlin中将UUID用作ID?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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