Dgraph: How to find two entities that are not related

Created on 23 Apr 2018  Â·  6Comments  Â·  Source: dgraph-io/dgraph

example:
There are 5 entities:a,b,c,d,e.
a like b
c like b
c like e
How to find the entities that not like b?

kinquestion

Most helpful comment

I am assuming all entities have a name, if not you could use some other predicate for has.

{
  allEntities as var(func: has(name)) @filter(NOT eq(name, "b"))

  likeB as var(func: uid(allEntities)) @cascade {
    name
    like @filter(eq(name, "b"))
  }

  # Subtract those who like B from all entities.
  me(func: uid(allEntities)) @filter(NOT uid(likeB)) {
    name
  }
}

All 6 comments

have you tried using @cascade ?

I am assuming all entities have a name, if not you could use some other predicate for has.

{
  allEntities as var(func: has(name)) @filter(NOT eq(name, "b"))

  likeB as var(func: uid(allEntities)) @cascade {
    name
    like @filter(eq(name, "b"))
  }

  # Subtract those who like B from all entities.
  me(func: uid(allEntities)) @filter(NOT uid(likeB)) {
    name
  }
}

index consume so many time while putting too many data into dgraph, but function should be used in some predicates which have been indexed, i am in trouble now.

Sorry, I'm not following the concern here, @shanghai-Jerry .

@pawanrawal Thanks,Will this lead to full tables scan?

allEntities as var(func: has(name)) @filter(NOT eq(name, "b"))

This would lead to a scan over the keys of predicate name. Key scans are really fast though. This isn't a bug, but questions. So, closing the issue.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

andrewsmedina picture andrewsmedina  Â·  4Comments

yupengfei picture yupengfei  Â·  4Comments

marvin-hansen picture marvin-hansen  Â·  4Comments

janardhan1993 picture janardhan1993  Â·  3Comments

MichelDiz picture MichelDiz  Â·  3Comments