Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Intersect query for tinkerpop3 gremlin

I am using DSE-5.0.5 and DSE-studio and want to write a query in gremlin inside notebook graph. Is there a intersect query that could give me common elements between two sets returned via traversal in tinkerpop3 .

I have written this query:

g.V().has('name','Person1').outE('BELONGS').inV().inE('HAS').outV().as('x').inE('HAS').outV().as('y').inE('HAS').outV().has('name','App1').select('x').inE('HAS').outV().hasLabel('Org').as('p').repeat(out()).until(outE().hasLabel('IS')).as('a1').select('y').inE('HAS').outV().hasLabel('Class').repeat(inE('IS').dedup().otherV()).until(inE().hasLabel('HAS')).as('a2').select('a1','a2')

So I want an intersection of sets a1 and a2. Or is there an efficient way of writing this which could give me that?

like image 613
Varun Tahin Avatar asked May 15 '26 22:05

Varun Tahin


1 Answers

It would have been helpful to have a sample graph, but I think this should work:

g.V().has("name","Person1").
  out("BELONGS").in("HAS").dedup().as("x").
  in("HAS").filter(__.in("HAS").has("name","App1")).store("y").
  select("x").dedup().in("HAS").hasLabel("Org").
  repeat(out()).until(outE().hasLabel("IS")).store("a").cap("y").
  unfold().in("HAS").hasLabel("Class").
  repeat(inE("IS").dedup().otherV()).until(inE("HAS")).
  where(within("a"))
like image 103
Daniel Kuppitz Avatar answered May 19 '26 02:05

Daniel Kuppitz