Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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?

like image 318
cmant Avatar asked Mar 24 '18 15:03

cmant


1 Answers

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.

like image 123
stephen mallette Avatar answered Sep 17 '22 17:09

stephen mallette