Gremlin: “The provided traverser does not map to a value” when using project

我的梦境 提交于 2019-12-23 09:31:43

问题


In the Modern graph, I want to get for each person the name and the list of names of software he created. So I tried the following query

g.V().hasLabel('person').project('personName','softwareNames').
                         by(values('name')).
                         by(out('created').values('name').aggregate('a').select('a'))

but I get the error

The provided traverser does not map to a value: v[2]->[VertexStep(OUT,[created],vertex), PropertiesStep([name],value), AggregateStep(a), SelectOneStep(last,a)]

The problem seems to be that vertex 2 has no "created" edges.

The query works if I run it only on vertices with at least one "created" edge, e.g. for vertex 4 ("V(4)" instead of "V()"), the result is

==>[personName:josh,softwareNames:[ripple,lop]]

How can I get an empty list of software names for vertex 2, instead of the error?


回答1:


You can simplify your Gremlin to this:

gremlin> g.V().hasLabel('person').
......1>   project('personName','softwareNames').
......2>     by('name').
......3>     by(out('created').values('name').fold())
==>[personName:marko,softwareNames:[lop]]
==>[personName:vadas,softwareNames:[]]
==>[personName:josh,softwareNames:[ripple,lop]]
==>[personName:peter,softwareNames:[lop]]

The by() modulator only does a next() on the inner traversal passed to it, so you need to reduce the results yourself - in this case fold() does that and handles the situation where you have an empty result.



来源:https://stackoverflow.com/questions/49466453/gremlin-the-provided-traverser-does-not-map-to-a-value-when-using-project

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!