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?
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With