开发者

How to chain commands in Gremlin?

The follow开发者_运维问答ing 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.

http://markorodriguez.com

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜