'as' 在 'where' 中使用时如何工作?

How does 'as' work when used inside 'where'?

学习 gremlin 并查看示例我看到在 where 步骤中使用 as 来匹配之前标记的步骤。

例如,from official recipes page,一个顶点用 as 标记为 'v',稍后在合并内部它会查找 inE,其中 outV 等于 'v',但它再次使用 as 这样做:

gremlin> g.V().has('person','name','vadas').as('v').
           V().has('software','name','ripple').
           coalesce(__.inE('created').where(outV().as('v')),
                    addE('created').from('v').property('weight',0.5))

如果我只是阅读参考文档,这个查询在我看来就像他们只是将 outV 步骤标记为 'v',仅此而已。

as的这个功能似乎没有在参考文档中记录,只在示例中显示,没有特别提及。

前面的查询是否和下面的实现一样?

gremlin> g.V().has('person','name','vadas').as('v').
           V().has('software','name','ripple').
           coalesce(__.inE('created').where(outV().where(eq('v'))),
                    addE('created').from('v').property('weight',0.5))

这仅仅是缺少文档,还是我遗漏了什么?

是说as在'where'里面有特殊的含义,对吗?或者还有其他需要考虑的因素吗?

是的 - as()where() 中有特殊含义。它被简要描述为 select()/where() usage (see item 3) and in the match()/where() usage 的一部分。基本上,当您以这种方式编写查询时,您使用的是 where() 及其变量绑定形式,相当于您在第二个查询中展示的更直接的形式。就个人而言,我倾向于发现绑定形式的可读性稍差,但这取决于我猜测的过滤器的性质,有时它代表了构建查询的最清晰的方式。

如您所见,as 步骤在 where 步骤中的处理方式不同,允许在 where 步骤之外创建的步骤标签被视为 where 中的标签步骤而不是文字字符串。

这里有一篇文章

http://www.kelvinlawrence.net/book/PracticalGremlin.html#patternwhere