Combine two queries to perform only one
can someone help me figureout how I can combine those two queries?
groups = f"g.V().hasLabel('Groups').as('group_data').elementMap().range({start_index}, {end_index}).toList()"
users = f"g.V().hasLabel('Groups').as('group_data').bothE('memberOf').otherV().as('members').select('members').by(elementMap()).range({start_index}, {end_index}).toList()"
Solution:Jump to solution
Simple solution is to use
union
step https://tinkerpop.apache.org/docs/current/reference/#union-step
something like
g.union(
V().hasLabel('Groups').range({start_index}, {end_index}).elementMap(), V().hasLabel('Groups').out().range({start_index}, {end_index}).elementMap()))
...5 Replies
Solution
Simple solution is to use
union
step https://tinkerpop.apache.org/docs/current/reference/#union-step
something like
g.union(
V().hasLabel('Groups').range({start_index}, {end_index}).elementMap(), V().hasLabel('Groups').out().range({start_index}, {end_index}).elementMap()))
other possible way is like
g.V().as('V0').out().as('V1').range({start_index}, {end_index}).select('V0','V1').by(elementMap())
I'm not sure which is more appropriate in this case...Hello there, I am using AWS neptune and tried the informed queries you mentioned.
The second one is a very similar we did before but it still has the structure:
and we wanted to have
the first query we couldn't make it work at all
receiving 'GraphTraversal' object is not callable even adding __.V()
Looks like Neptune does not support starting
union
step, but it's better to check with Neptune guys.
for such a result structure is more suitable group
step
g.V().hasLabel('Groups').group().by(out())
with pagination a bit more complex
g.V().filter(out().count().is(gt(0))).range({start_index}, {end_index}).group().by(out())
prior to there being a
union()
start step you had to cheat. g.inject(0).union(...)
which should work on Neptune but I don't think it will perform well depending on the amount of data involved. Neptune will have support for the union()
start step soon enough though when it supports TinkerPop 3.7.x. That said, i'm not sure a union()
start step is what you want here. Based on the output you asked for, you really just want groups and their players, right? Isn't this just a case for a simple group()
?