Search code examples
gremlintinkerpop3

Gremlin: Get unique properties of edges leaving from vertex


I have the id of a vertex and there are multiple edges leaving from it with the properties: version, status, name. There can be multiple edges with the same version and status but with a different name.

How can I get all the unique version and status combinations starting from the vertex id?

I have tried this:

G.V("1").outE()
  .group()
  .by(select("version", "status"))
  .by(select("version", "status"))

But it is not returning anything (the result is an empty map).

I have tried this:

G.V("1").outE()
  .group()
  .by(values("version", "status"))
  .by(values("version", "status"))

and

G.V("1").outE()
  .group()
  .by(values("status", "version"))
  .by(values("status", "version"))

Both of which are returning a map with one element key 1 value 1.

I was expecting a list of objects with properties like status=INACTIVE and version=1.


Solution

  • To get the unique pairings you need to convert each edge to the pair you want and then use dedup() to get the unique set.

    g.V("1").outE().map(values('version','status').fold()).dedup()