下面的命令有效
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
为什么?
最佳答案
快速回答:您需要迭代管道。
长答案:在 Gremlin REPL 中,如果您的最后一条语句是迭代器或可迭代的,迭代将自动为您发生。但是,如果您的最后一条语句不是(例如 println t),那么您必须手动迭代您的迭代器/可迭代对象。
例如,要使您之前的命令生效,请执行(注意 >>-1):
t = new Table(); g.V.as('id').as('properties').table(t){it.id}{it.map}>>-1; print t
有关更多信息,请阅读 Gremlin 文档的故障排除部分中的第一期: https://github.com/tinkerpop/gremlin/wiki/Troubleshooting
接下来,虽然您没有问这个问题,但当您连续执行两个 as() 步骤时,您会遇到排序问题。 AsPipe 是一个 MetaPipe,因为它包装了它之前的管道/步骤(Gremlin 基于 Pipes )。最好这样做:
g.V.as('id')._.as('properties').table(t){it.id}{it.map}
即在两个as()步骤之间插入一个identity步骤。
希望对你有帮助, 马尔科。
关于graph - 如何在 Gremlin 中链接命令?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7433802/