[英]Check the sack() value in a gremlin query
We have a query to find the possible paths to a node.我们有一个查询来查找节点的可能路径。 We represented ABC paths with numbers as shown in the table and we are using bitwise and operation to see available paths to a node.
我们用数字表示 ABC 路径,如表中所示,我们使用按位和运算来查看节点的可用路径。 We are repeating the query if there is at least one available path (A, B or C) to a node (values('availablePath').is(gt(0))).
如果至少有一个到节点的可用路径(A、B 或 C)(values('availablePath').is(gt(0))),我们将重复查询。 However, we want to stop the query if the sack value is 0 since it does not make sense to continue traversing after the Node 3 because sack value is 0, which means that you can not access node 3 by A, B or C paths.
但是,如果 sack 值为 0,我们希望停止查询,因为 sack 值为 0,因此在节点 3 之后继续遍历没有意义,这意味着您无法通过 A、B 或 C 路径访问节点 3。 Is there a way to get the sack value and stop traversing if it is 0?
有没有办法获取 sack 值并在它为 0 时停止遍历?
Our query is:我们的查询是:
g.withSack(7).
V().has('id','1')
local(
repeat(bothE().where(values('availablePath').is(gt(0))).
sack{f,l -> f & l}.
by('availablePath').
otherV().
simplePath().as('node')).
emit().
sack().as('path')).
select('node','path').
by().
by().
dedup()
Sample graph creation query:示例图创建查询:
g.addV('node').property('id','1').as('1')
.addV('node').property('id','2').as('2')
.addV('node').property('id','3').as('3')
.addV('node').property('id','4').as('4')
.addE('edge').property('availablePath',3).from('1').to('2').as('edge1')
.addE('edge').property('availablePath',4).from('2').to('3').as('edge2')
.addE('edge').property('availablePath',7).from('3').to('4').as('edge3')
Traversal begins from node 1.遍历从节点 1 开始。
You can test the sack
value inside the where
step as follows:您可以在
where
步骤中测试sack
值,如下所示:
gremlin> g.withSack(7).
......1> V().has('id','1').
......2> local(
......3> repeat(bothE().where(values('availablePath').is(gt(0)).and().sack().is(gt(0))).
......4> sack{f,l -> f & l}.
......5> by('availablePath').
......6> otherV().
......7> simplePath().as('node')).
......8> emit().
......9> sack().as('path')).
.....10> select('node','path').
.....11> by().
.....12> by().
.....13> dedup()
==>[node:v[4],path:3]
==>[node:v[6],path:0]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.