gremlinify:https://gremlify.com/l3gujyc2e5 请执行查询2和2.1来查看差异。
我在 Cosmos Graph Db 中有一个非循环单向图。
我的图有 2 种类型的顶点:
每个处理器获取 1 件或更多物品并生产 1 件或更多物品。
问题陈述: 给定一些 itemsList,disabledProcessorsList,从 itemsList 中的项开始遍历图形,直到路径耗尽或到达 disabledProcessorsList 中的任何处理器。
例如:
项目列表:'i6'
禁用处理器列表:'p12','p13','p14'
查询:
g.V().has('ItemDefinition','ItemName', within('i26'))
.until(__.outE().count().is(0))
.repeat(out().hasLabel('ProcessorDefinition')
.not(or( has('ProcessorName', within('p12','p13','p14'))))
.store('ProcessorsInPath').out())
.select('ProcessorsInPath').unfold().dedup()
.project('Processor', 'InputItems', 'OutputItems')
.by(__.valueMap('ProcessorName').select('ProcessorName'))
.by(__.in().values('ItemName').order().fold())
.by(__.out().values('ItemName').order().fold())
在上面的查询中,当向下遍历时,我只是收集标记为 ProcessorDefinition 的顶点并列出所有其输入和输出
上述查询的预期输出:
[
{
"Processor": [
"p11"
],
"InputItems": [
"i25",
"i26",
"i27",
"i28"
],
"OutputItems": [
"i29"
]
}
]
仅供参考..即使p13不在disabledProcessors中,预期输出也应该与p11相同,如果不遍历禁用的p12,p11就无法到达p13
上述查询的实际输出:
[]
如何编写查询以获得预期的输出?
谢谢!
使用 cap() 而不是 store() 解决了我的问题。看起来这与 store() 的惰性求值有关。
cap() 将强制对之前的所有步骤进行急切评估,与 Barrier() 非常相似。事实上,你可以将 cap(xxx) 视为 Barrier().select(xxx) 的简写
来源:https://www.datastax.com/blog/gremlin-recipes-7-variables-handling