How to get "friends" child not 'owned' by the friend's parent?

35 views
Skip to first unread message

Sergio Cardone

unread,
Feb 18, 2022, 11:41:42 PM2/18/22
to Gremlin-users
In my schema I have teams connected to another team by the edge is_friends_with, each team has players, and (note this) player can be owned by more than one team. 

Starting from a team (A) I would like to get the list of players of his friend, excluding the players owned by both teams (A and his friend).

Schermata 2022-02-18 alle 18.56.48.jpg

The result should be something like:

[ { "Player": "Icardi",
    "Teams": ["Valladolid"] 
 },
 { "Player": "Kroll", 
   "Teams": ["Valladolid"] 
 }, 
 { "Player": "Baggio", 
   "Teams": ["Eagles"] 
 }, 
 { "Player": "Papin", 
    "Teams": ["Valladolid","Eagls"] 
 }, ]

I tried to build the query but I'm too noob yet to get the best one. 

Can you help me to put me.... on the right path :) ?

Thanks a lot!

Here the schema used:

g.addV('team').as('1'). property(single, 'name', 'Eagles'). addV('player').as('2'). property(single, 'name', 'Zico').addV('team'). as('3'). property(single, 'name', 'team A'). addV('team').as('4'). property(single, 'name', 'Horses'). addV('player').as('5'). property(single, 'name', 'Papin'). addV('player').as('6'). property(single, 'name', 'Ronaldo'). addV('player').as('7'). property(single, 'name', 'Visco'). addV('player').as('8'). property(single, 'name', 'Baggio'). addV('tournament').as('9'). addV('team').as('10'). property(single, 'name', 'Valladolid'). addV('player').as('11'). property(single, 'name', 'Kroll'). addV('player').as('12'). property(single, 'name', 'Icardi'). addE('owned').from('1').to('5').addE('owned'). from('1').to('6').addE('owned').from('1'). to('8').addE('owned').from('3').to('6'). addE('owned').from('3').to('7'). addE('created').from('3').to('9'). addE('is_friends_with').from('3').to('10'). addE('is_friends_with').from('3').to('1'). addE('owned').from('4').to('8').addE('owned'). from('4').to('2').addE('owned').from('4'). to('5').addE('owned').from('4').to('7'). addE('invited').from('9').to('1'). addE('invited').from('9').to('4'). addE('owned').from('10').to('11'). addE('owned').from('10').to('12'). addE('owned').from('10').to('5')

Stark Arya

unread,
Feb 19, 2022, 5:05:51 AM2/19/22
to gremli...@googlegroups.com
gremlin>  g.V().has("name", "team A").sideEffect(__.out("owned").hasLabel("player").aggregate("my_player").limit(1)).both("is_friends_with").hasLabel("team").flatMap(__.as("team2").out("owned").hasLabel("player").as("friends_player").where(without("my_player")).as("friends_player2").select("team2", "friends_player2")).group().by(select("friends_player2")).by(select("team2").fold()).unfold().project("Player", "Teams").by(select(keys).values("name")).by(select(values).unfold().values("name").fold())
==>[Player:Baggio,Teams:[Eagles]]
==>[Player:Kroll,Teams:[Valladolid]]
==>[Player:Icardi,Teams:[Valladolid]]
==>[Player:Papin,Teams:[Valladolid,Eagles]]
gremlin>

I think this is for you, no thanks!

在 2022年2月19日,12:41,Sergio Cardone <ser...@ascweb.it> 写道:

In my schema I have teams connected to another team by the edge is_friends_with, each team has players, and (note this) player can be owned by more than one team. 

Starting from a team (A) I would like to get the list of players of his friend, excluding the players owned by both teams (A and his friend).

<Schermata 2022-02-18 alle 18.56.48.jpg>

The result should be something like:

[ { "Player": "Icardi",
    "Teams": ["Valladolid"] 
 },
 { "Player": "Kroll", 
   "Teams": ["Valladolid"] 
 }, 
 { "Player": "Baggio", 
   "Teams": ["Eagles"] 
 }, 
 { "Player": "Papin", 
    "Teams": ["Valladolid","Eagls"] 
 }, ]

I tried to build the query but I'm too noob yet to get the best one. 

Can you help me to put me.... on the right path :) ?

Thanks a lot!

Here the schema used:

g.addV('team').as('1'). property(single, 'name', 'Eagles'). addV('player').as('2'). property(single, 'name', 'Zico').addV('team'). as('3'). property(single, 'name', 'team A'). addV('team').as('4'). property(single, 'name', 'Horses'). addV('player').as('5'). property(single, 'name', 'Papin'). addV('player').as('6'). property(single, 'name', 'Ronaldo'). addV('player').as('7'). property(single, 'name', 'Visco'). addV('player').as('8'). property(single, 'name', 'Baggio'). addV('tournament').as('9'). addV('team').as('10'). property(single, 'name', 'Valladolid'). addV('player').as('11'). property(single, 'name', 'Kroll'). addV('player').as('12'). property(single, 'name', 'Icardi'). addE('owned').from('1').to('5').addE('owned'). from('1').to('6').addE('owned').from('1'). to('8').addE('owned').from('3').to('6'). addE('owned').from('3').to('7'). addE('created').from('3').to('9'). addE('is_friends_with').from('3').to('10'). addE('is_friends_with').from('3').to('1'). addE('owned').from('4').to('8').addE('owned'). from('4').to('2').addE('owned').from('4'). to('5').addE('owned').from('4').to('7'). addE('invited').from('9').to('1'). addE('invited').from('9').to('4'). addE('owned').from('10').to('11'). addE('owned').from('10').to('12'). addE('owned').from('10').to('5')

--
You received this message because you are subscribed to the Google Groups "Gremlin-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gremlin-user...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/gremlin-users/68f222f2-2b2d-4328-95d6-0689c61fab7dn%40googlegroups.com.
<Schermata 2022-02-18 alle 18.56.48.jpg>

Sergio Cardone

unread,
Feb 19, 2022, 9:57:57 AM2/19/22
to Gremlin-users
Thanks! It looks great!!! I have to study it to learn more about it! I really appreciated your help!!!! THANKS!

Kelvin Lawrence

unread,
Feb 19, 2022, 5:38:11 PM2/19/22
to Gremlin-users

Sergio Cardone

unread,
Feb 20, 2022, 2:33:34 AM2/20/22
to Gremlin-users
Thanks Kelvin! I'm happy twice! First because of your clear and light answer and second because it is very close to my own but... it works! So, I can learn and fix it :D I didn't use the group and it was the key. THANKS!
Reply all
Reply to author
Forward
0 new messages