Suppose I want to query the Neptune graph with "group-by" on one property (or more), and I want to get back the list of vertices too.
Let's say, I want to group-by on ("city", "age") and want to get the list of vertices too:
[
{"city": "SFO", "age": 29, "persons": [v[1], ...]},
{"city": "SFO", "age": 30, "persons": [v[10], v[13], ...]},
...
]
Or, get back the vertex with its properties (as valueMap
):
[
{"city": "SFO", "age": 29, "persons": [[id:1,label:person,name:[marko],age:[29],city:[SFO]], ...]},
...
]
AFAIK, Neptune doesn't support lambda nor variable assignments. is there a way to do this with one traversal and no lambdas?
Update: I'm able to get the vertices, but without their properties (with valueMap
).
Query:
g.V().hasLabel("person").group().
by(values("city", "age").fold()).
by(fold().
match(__.as("p").unfold().values("city").as("city"),
__.as("p").unfold().values("age").as("age"),
__.as("p").fold().unfold().as("persons")).
select("city", "age", "persons")).
select(values).
next()
Output:
==>[city:SFO,age:29,persons:[v[1]]]
==>[city:SFO,age:27,persons:[v[2],v[23]]]
...