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:
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()))...
Jump to solution
5 Replies
Solution
Valentyn Kahamlyk
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()))
Valentyn Kahamlyk
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...
Andre Pinto
Andre PintoOP7mo ago
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:
groupdata1
player1
groupdata1
player2
groupdata1
player3

groupdata2
player1
groupdata2
player2
groupdata2
player3
groupdata1
player1
groupdata1
player2
groupdata1
player3

groupdata2
player1
groupdata2
player2
groupdata2
player3
and we wanted to have
groupdata1
player1
player2
player3
groupdata2
player1
player2
player3
groupdata1
player1
player2
player3
groupdata2
player1
player2
player3
the first query we couldn't make it work at all receiving 'GraphTraversal' object is not callable even adding __.V()
Valentyn Kahamlyk
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())
spmallette
spmallette7mo ago
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()?
g.V().hasLabel('Groups').
group().
by(elementMap()).
by(bothE('memberof').
otherV().
elementMap().fold())
g.V().hasLabel('Groups').
group().
by(elementMap()).
by(bothE('memberof').
otherV().
elementMap().fold())
Want results from more Discord servers?
Add your server