Trouble with uid_in

Hey there. Having a little trouble. Have a graph with a bunch of random nodes and connections.

bbbb(func: uid(0x5,0x9)) {
    name@en
  	name
  	uid
    friend  {
      name@en
      uid
      name
	}
}

yields

but if i try to get only the intersection of the two sets (i.e. those 5 in the middle), which i think i should do like so:

 bbbb(func: uid(0x5)) {
    name@en
  	name
  	uid
    friend @filter(uid_in(friend, 0x9)) {
      name@en
      uid
      name
	}
}

for some reason I only get the node labeled “node611” and two of its descendant nodes that aren’t in the intersection at all.

What am I doing wrong?

Thanks!

I think there is some confusion here about what uid_in is supposed to do.

Say node with uid 5 has a set of friends A.

5 - friend => [A]

The uid_in would filter and retain the nodes in set A which have a friend with uid 0x9. Note that edges in Dgraph are not bidirectional so you get nodes which are friend of 0x5 and who have 0x9 as a friend. Node with uid 0x9 doesn’t need to be friends with this set.

To get common friends, you could do something like

{
  var(func: uid(0x5)) {
    friend_5 as friend
  }

  var(func: uid(0x9)) {
    friend_9 as friend
  }

  commonFriends(func: uid(friend_5)) @filter(uid(friend_9)) { 
    name@en:.
    uid
  }
}

Thank you! I misinterpreted the manual’s description of uid_in.

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.