Reputation: 936
I am a newbie in the graph databases world, and I made a query to get leaves of the tree, and I also have a list of Ids. I want to merge both lists of leaves and remove duplicates in a new one to sum property of each. I cannot merge the first 2 sets of vertex
g.V().hasLabel('Group').has('GroupId','G001').repeat(
outE().inV()
).emit().hasLabel('User').as('UsersList1')
.V().has('UserId', within('001','002')).as('UsersList2')
.select('UsersList1','UsersList2').dedup().values('petitions').sum().unfold()
Regards
Upvotes: 0
Views: 177
Reputation: 10904
There are several things wrong in your query:
V().has('UserId', within('001','002'))
for every user that was found by the first part of the traversalselect('UsersList1','UsersList2')
creates pairs of usersvalues('petitions')
tries to access the property petitions
of each pair, this will always failThe correct approach would be:
g.V().has('User', 'UserId', within('001','002')).fold().
union(unfold(),
V().has('Group','GroupId','G001').
repeat(out()).until(hasLabel('User'))).
dedup().
values('petitions').sum()
Upvotes: 2
Reputation: 1419
I didn't test it, but I think the following will do:
g.V().union(
hasLabel('Group').has('GroupId','G001').repeat(
outE().inV()
).until(hasLabel('User')),
has('UserId', within('001','002')))
.dedup().values('petitions').sum()
In order to get only the tree leaves, it is better to use until
. Using emit
will output all inner tree nodes as well.
union
merges the two inner traversals.
Upvotes: 1