将Gremlin GraphTraversal结果与字符串连接 [英] Concatenate Gremlin GraphTraversal result with string
问题描述
在这个非常简单的示例中,我尝试添加一个新的顶点,该顶点应被标记为现有的顶点,但要附加一些前缀:
In this very simple example I am trying to add a new vertex which should be labeled like an existing vertex but with some prefix attached:
g.V(1).addV('prefix_' + label()).valueMap(true)
我在这里想念什么?显然不是字符串,但是我该如何序列化呢?
What am I missing here? It's clearly not a String, but how would I serialize that?
gremlin> g.V(1).label()
==>Person
gremlin> g.V(1).constant(label())
==>[LabelStep]
推荐答案
今天,Gremlin不提供内置的字符串连接功能.如果这样做的话,那就太好了.这意味着您今天最好的选择是使用内联闭包/lambda.这是一个使用TinkerGraph和航路图的示例.
Gremlin today does not provide a built in string concatenation function. It would be nice if it did. That means your best alternative today is to use an in line closure/lambda. Here is an example using TinkerGraph and the air-routes graph.
gremlin> g.V(3).map {"prefix_" + it.get().label}.as('a').addV(select('a'))
==>v[60867]
gremlin> g.V(60867).label()
==>prefix_airport
请注意,并非所有的图形数据库都允许闭包,因此不能假定其在启用了TinkerPop的任何Graph DB后端上都可以通用.
Note that not all graph databases allow closures so this cannot be assumed to work universally on any TinkerPop enabled Graph DB backend.
这篇关于将Gremlin GraphTraversal结果与字符串连接的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!