Details
-
Improvement
-
Status: Open
-
Major
-
Resolution: Unresolved
-
3.3.0, 3.2.6
-
None
-
None
Description
Working on this SO question: https://stackoverflow.com/questions/46962237/how-to-perform-cross-join-on-different-vertices-in-gremlin-tinkerpop/46977603
...I noticed that the connected components query randomly loses the vertex labels.
Init Graph:
graph = TinkerGraph.open() g = graph.traversal() a = graph.addVertex(label, "person", "user", "A") b = graph.addVertex(label, "person", "user", "B") c = graph.addVertex(label, "person", "user", "C") d = graph.addVertex(label, "person", "user", "D") one = graph.addVertex('rec_id') one.property('ids', '1') two = graph.addVertex('rec_id') two.property('ids', '2') three = graph.addVertex('rec_id') three.property('ids', '3') four = graph.addVertex('rec_id') four.property('ids', '4') five = graph.addVertex('rec_id') five.property('ids', '5') a.addEdge('part_of',one) a.addEdge('part_of',two) b.addEdge('part_of', three) b.addEdge('part_of',four) c.addEdge('part_of',five) d.addEdge('part_of',four) d.addEdge('part_of',two) g = graph.traversal().withComputer()
Query:
g.V(). emit(cyclicPath().or().not(both())). repeat(both()). until(cyclicPath()). aggregate("p").by(path()).cap("p"). unfold().limit(local, 1).dedup(). map(__.as("v").select("p").unfold(). filter(unfold().where(eq("v"))). unfold().dedup().order().by(id).fold()).dedup(). project("Users","associated_ids"). by(unfold().label().fold()). by(unfold().label().fold())
Sample Output:
gremlin> g.V(). ......1> emit(cyclicPath().or().not(both())). ......2> repeat(both()). ......3> until(cyclicPath()). ......4> aggregate("p").by(path()).cap("p"). ......5> unfold().limit(local, 1).dedup(). ......6> map(__.as("v").select("p").unfold(). ......7> filter(unfold().where(eq("v"))). ......8> unfold().dedup().order().by(id).fold()).dedup(). ......9> project("Users","associated_ids"). .....10> by(unfold().label()./*hasLabel("person").*/fold()). .....11> by(unfold().label()./*hasLabel("rec_id").*/fold()) ==>[Users:[person,person,person,vertex,vertex,vertex,vertex],associated_ids:[person,person,person,vertex,vertex,vertex,vertex]] ==>[Users:[vertex,rec_id],associated_ids:[vertex,rec_id]] gremlin> g = graph.traversal().withComputer() ==>graphtraversalsource[tinkergraph[vertices:9 edges:7], graphcomputer] gremlin> g.V(). ......1> emit(cyclicPath().or().not(both())). ......2> repeat(both()). ......3> until(cyclicPath()). ......4> aggregate("p").by(path()).cap("p"). ......5> unfold().limit(local, 1).dedup(). ......6> map(__.as("v").select("p").unfold(). ......7> filter(unfold().where(eq("v"))). ......8> unfold().dedup().order().by(id).fold()).dedup(). ......9> project("Users","associated_ids"). .....10> by(unfold().label()./*hasLabel("person").*/fold()). .....11> by(unfold().label()./*hasLabel("rec_id").*/fold()) ==>[Users:[person,person,person,rec_id,vertex,vertex,vertex],associated_ids:[person,person,person,rec_id,vertex,vertex,vertex]] ==>[Users:[vertex,rec_id],associated_ids:[vertex,rec_id]]