g.V().hasLabel('employee').fold().as("emp", "count")
.select("emp", "count")
.by(range(local, 0, 2).elementMap())
.by(count(local));
The above query is working fine when the range interval is 1 (OR) total number of return vertex is 1.
If it has more than one vertex or the range interval is increased, getting the UnsupportedOperationException exception. How to solve?
The same query works without elementMap(), however, it's needed in application just vertex id is not helpful
The
UnsupportedOperationexception is because you are creating essentially a list of vertices when therangeyields more than one result. The full error is actually going to be something like:Which gives us a clue. The query expected an element, like a vertex or an edge but instead got a list of vertices.
When the
rangeis from 0 to 2, the result will be of the form:You will need to do something like
for the query to work correctly.
Note that the query can be rewritten using
project: