如何在 Gremlin 中链接命令?
以下命令有效
t = new Table(); g.V.as('id').as('properties').table(t){it.id}{it.map}
print t
以下命令有效
t = new Table();
g.V.as('id').as('properties').table(t){it.id}{it.map}; print t
以下命令无效
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 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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
快速回答:您需要迭代您的管道。
长答案:在 Gremlin REPL 中,如果您的最后一个语句是迭代器或可迭代器,迭代将会自动发生。但是,如果您的最后一条语句不是(例如 println t),那么您必须手动迭代您的迭代器/可迭代器。
例如,要使之前的命令正常工作,请执行以下操作(请注意 >>-1):
有关详细信息,请阅读 Gremlin 文档的故障排除部分中的第一个问题:
https://github.com/tinkerpop/gremlin/wiki/Troubleshooting
接下来,当您没有问这个问题,当你连续有两个 as() 步骤时,你会遇到排序问题。 AsPipe 是一个 MetaPipe,因为它包装了之前的 Pipe/step(Gremlin 基于 Pipes)。最好这样做:
即在两个 as() 步骤之间插入一个恒等步骤。
希望有帮助,
马可.
http://markorodriguez.com
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):
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:
That is, insert an identity step between the two as() steps.
Hope that helps,
Marko.
http://markorodriguez.com