2
votes

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?

1

1 Answers

3
votes

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"))