如何链接Gremlin中的命令? [英] How to chain commands in Gremlin?
问题描述
以下命令可以工作
t = new Table(); gVas('id')。as('properties')。table(t){it.id} {it.map}
print t
以下命令可以工作
t = new Table(); $('id')。as('properties')。table(t){it.id} {it.map};
g.V.as打印t
以下命令不起作用
t = new Table(); 。g.V.as( ID),为(属性)表(t)的{it.id} {it.map};打印t
为什么?
快速回答:您需要迭代您的管道。
长答案:在Gremlin REPL中,如果最后一条语句是迭代器或迭代器,迭代将自动发生。然而,如果你最后一条语句不是(例如println t),那么你必须手动迭代你的迭代器/ iterable。
例如,为了使你以前的命令工作, (注意>> - 1): t = new Table(); g.V.as( ID),为(属性)表(t)的{it.id} {it.map}> -1个; print t
有关更多信息,请阅读Gremlin文档的疑难解答部分中的第一个问题:
https://github.com/tinkerpop/gremlin/wiki/Troubleshooting 接下来,虽然你没有问这个问题,但是当你连续有两个as()步时,你会遇到排序问题。 AsPipe是一个MetaPipe,它包裹了之前的Pipe /步骤(Gremlin基于 Pipes )。最好这样做:
gVas('id')._。as。('properties')。table t){it.id} {it.map}
也就是说,在两个作为()的步骤。
希望有帮助,
Marko。
The following command works
t = new Table(); g.V.as('id').as('properties').table(t){it.id}{it.map}
print t
The following command works
t = new Table();
g.V.as('id').as('properties').table(t){it.id}{it.map}; print t
The following command doesn't work
t = new Table(); g.V.as('id').as('properties').table(t){it.id}{it.map}; print t
Why?
The fast answer: You need to iterate your pipeline.
The long answer: In the Gremlin REPL, iteration will happen for you automagically if your last statement is an iterator or iterable. However, if you last statement is not (e.g. println t), then you must manually iterate your iterator/iterable.
For example, to make your previous command work, do (note the >>-1):
t = new Table(); g.V.as('id').as('properties').table(t){it.id}{it.map}>>-1; print t
For more information, read the first issue in the troubleshooting section of the Gremlin documentation: https://github.com/tinkerpop/gremlin/wiki/Troubleshooting
Next, while you didn't ask this question, you will run into ordering issues when you have two as() steps in a row. The AsPipe is a MetaPipe in that it wraps the Pipe/step previous to it (Gremlin is based on Pipes). It is best to do this:
g.V.as('id')._.as('properties').table(t){it.id}{it.map}
That is, insert an identity step between the two as() steps.
Hope that helps, Marko.
这篇关于如何链接Gremlin中的命令?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!