0

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.

Thef
  • 5
  • 2
  • Need help with my query, stuck with this for long https://stackoverflow.com/questions/73036082/gremlin-simple-path-query-to-get-path-based-on-first-edge-encountered-property – Parvesh Kumar Jul 22 '22 at 10:44

1 Answers1

0

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()
stephen mallette
  • 45,298
  • 5
  • 67
  • 135
  • Thanks, this is very close to what I am looking for. Now I am getting a map where the key is a list of 2 items (status and version) and the value is the list of edges. What I need is a list of the keys (I am not interested in the edges, only the unique combinations of status and version). – Thef Apr 19 '21 at 11:15
  • Perfect! Just to make it clear, I actually needed this: `g.V("1").outE().map(valueMap("version", "status").fold()).dedup().unfold()` so now I have a stream of `Map` where `key` is `"version"` or `"status"`. – Thef Apr 19 '21 at 12:11
  • then it's just `g.V("1").outE().valueMap('version','status').dedup()` i guess – stephen mallette Apr 19 '21 at 12:20