为什么这个带有select的gremlin查询不返回任何结果,但没有select,它就可以工作?
我有一个链表为什么这个带有select的gremlin查询不返回任何结果,但没有select,它就可以工作?,gremlin,Gremlin,我有一个链表B->C->G 它是在TinkerPop控制台中使用 graph = TinkerGraph.open() g = traversal().withEmbedded(graph) g.addV('TreeNodeEntity').property(single, 'Name', 'B').as('l1') g.addV('TreeNodeEntity').property(single, 'Name', 'C').as('l1').addE('PreviousSiblingEnti
B->C->G
它是在TinkerPop控制台中使用
graph = TinkerGraph.open()
g = traversal().withEmbedded(graph)
g.addV('TreeNodeEntity').property(single, 'Name', 'B').as('l1')
g.addV('TreeNodeEntity').property(single, 'Name', 'C').as('l1').addE('PreviousSiblingEntity').to(__.V().has('Name', 'B'))
g.addV('TreeNodeEntity').property(single, 'Name', 'G').as('l1').addE('PreviousSiblingEntity').to(__.V().has('Name', 'C'))
我尝试获取B
的所有兄弟姐妹
下面的小精灵脚本像我预期的那样返回C
和G
g.V().
has('Name', 'B').
as('l1').
repeat(__.
bothE('PreviousSiblingEntity').
otherV().
simplePath()
).
emit().
valueMap()
但是下面的脚本没有给我任何价值
g.V().
has('Name', 'B').
as('l1').
select('l1').
repeat(__.
bothE('PreviousSiblingEntity').
otherV().
simplePath()
).
emit().
valueMap()
背景:我想在as('l1')
和select('l1')
之间做一个.inE('ParentEntity').otherV().as('l2')
你能给我一个提示为什么第二个脚本没有给我结果吗?小精灵的路径(即TinkerPop的
路径
对象)和一个人在图形中穿过的路径之间有区别。我认为您希望simplePath()
在后者上工作,而它在前者上工作
遍历器在遍历步骤中进行转换。这些转换的历史记录是路径。您可以使用path()
步骤查看该历史记录:
gremlin> g.V().out().path()
==>[v[2],v[0]]
==>[v[5],v[2]]
但是,路径
不仅仅是图形元素,还可以包含其他内容:
gremlin> g.V().out().values('Name').path()
==>[v[2],v[0],B]
==>[v[5],v[2],C]
根据该定义,simplePath()
查找路径中的元素重复的情况,并将其过滤掉。通过执行g.V().has('Name','B')。as('l1')。选择('l1')
可以立即创建这样的重复,因此路径将被过滤掉:
gremlin> g.V().has('Name', 'B').as('l1').select('l1').path()
==>[v[0],v[0]]
gremlin> g.V().has('Name', 'B').as('l1').select('l1').simplePath()
gremlin>