我们可以在Gremlin图中更新顶点的主键吗?

huangapple go评论78阅读模式
英文:

Can we update the primary key of a vertex in gremlin graph?

问题

我有一个需求,需要更新gremlin图中顶点的主键。我有一个'policy'顶点,'policy_number'是该顶点的主键。现有的policy number值是'/a123',但我想删除policy_number中的特殊字符,并将其保留为'a123',而不影响其连接的边和顶点。在tinkerpop图文档中,我遇到了mergeV()函数,但我没有太多的示例来尝试它。有人可以帮助我找到适合我需求的任何有用的gremlin函数吗?

g.mergeV(["policy_number":"\84XXXXXX"]).option(Merge.onMatch,sideEffect(property(single,"policy_number","84XXXXXX")).constant([:]))

但是我得到了以下错误

error: illegal start of simple expression

g.mergeV(["policy_number":"\84XXXXXX"]).option(Merge.onMatch,sideEffect(property(single,"policy_number","84XXXXX")).constant([:]))

首先,我不确定上述语法是否会更新policy_number而不创建policy numbers列表作为其值,并且只创建一个值,而且不会影响其连接(边、顶点)。

如果有其他替代方法,而不是使用mergeV()呢?

英文:

I have a requirement where I need to update the primary key of a vertex in gremlin graph. I have a 'policy' vertex and 'policy_number' is the primarykey of the vertex. Existing policy number value is '/a123' but I want to delete the special character in the policy_number and keep it as 'a123' with out affecting its connected edges and vertices. In tinkerpop graph documentation I came across mergeV() function but I don't have too many examples to try it. Can some one help with any useful functions in gremlin that is suitable for my requirement.

g.mergeV(["policy_number":"\XXXXXX"]).option(Merge.onMatch,sideEffect(property(single,"policy_number","84XXXXXX")).constant([:]))

but I got the below error

> error: illegal start of simple expression
>
> g.mergeV(["policy_number":"\84XXXXXX"]).option(Merge.onMatch,sideEffect(property(single,"policy_number","84XXXXX")).constant([:]))

First thing, Im not sure if above syntax updates the policy_number with out creating a list of policy numbers as its value and create only one value and also not affecting its connections (edges,vertices).

Instead of mergeV() if there is any other alternative?

答案1

得分: 1

如果你的主键实际上只是一个属性,而不是节点ID,那么简单的property步骤就足够了。mergeV步骤是相当新的,可能你正在使用的数据库(我假设是DataStax)还不支持它。你可以尝试使用类似下面的代码:

g.V().has("policy_number","\XXXXXX").
  property(single,"policy_number","84XXXXXX")
英文:

If your primary key is actually just a property, and not the node ID, a simple property step should suffice. The mergeV step is quite new and it's possible that the database you are using (I assume DataStax from the tags) does not support it yet. You should be able to use something like this:

g.V().has("policy_number","\\84XXXXXX").
  property(single,"policy_number","84XXXXXX")

huangapple
  • 本文由 发表于 2023年8月8日 23:42:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76861155.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定