格雷姆林算术在哪里谓词



在这个问题中,使用前一个边属性值来过滤后一个边的Gremlin图遍历,我们可以使用where来比较边的属性。我不想只使用简单的neqeqgt。gremlin能在这两边支持算术吗?类似gtv('firstEdge', 0.2)g.V(1).outE().has('weight',1.0).as('firstEdge').inV().outE().as('secondEdge').filter((secondEdge-firstEdge) > 0.2)

我似乎在文件中找不到这样的东西。

有几种方法可以处理这种情况。对于只需要a+b < some value的简单查询,使用sack效果良好。例如,使用航线数据集:

g.withSack(0).
V('44').
repeat(outE('route').sack(sum).by('dist').inV().simplePath()).
times(2).
where(sack().is(lt(500))).
path().
by('code').
by('dist').
limit(2)

产生:

1   path[SAF, 369, PHX, 110, TUS]
2   path[SAF, 369, PHX, 119, FLG]

使用math步骤只需要再做一点工作:

让我们首先通过查询来了解math步骤在这种情况下是如何工作的,以获取一些路线距离之间的差异:

g.V('44').
outE('route').as('a').inV().
outE('route').as('b').inV().
project('b','a','diff').
by(select('b').values('dist')).
by(select('a').values('dist')).
by(math('b - a').by('dist')).
limit(3)

产生:

1   {'b': 1185, 'a': 549, 'diff': 636.0}
2   {'b': 6257, 'a': 549, 'diff': 5708.0}
3   {'b': 8053, 'a': 549, 'diff': 7504.0}

我们现在可以细化查询以找到差异小于100的路由。

g.V('44').
outE('route').as('a').inV().
outE('route').as('b').inV().
where(math('b - a').by('dist').is(lt(100))).
path().
by('code').
by('dist').
limit(3)

这给了我们:

1   path[SAF, 549, DFW, 430, MEM]
2   path[SAF, 549, DFW, 461, MCI]
3   path[SAF, 549, DFW, 550, STL]

如果愿意,也可以在计算中使用绝对值:

g.V('44').
outE('route').as('a').inV().
outE('route').as('b').inV().
where(math('abs(b - a)').by('dist').is(lt(100))).
path().
by('code').
by('dist').
limit(3)

最新更新