use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testRepeatWithEmitFirstPathWithPeriod.
@Test
public void testRepeatWithEmitFirstPathWithPeriod() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name.AA", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "c2");
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "c3");
b1.addEdge("bc", c1);
b1.addEdge("bc", c1);
b1.addEdge("bc", c2);
b1.addEdge("bc", c3);
Vertex d1 = this.sqlgGraph.addVertex(T.label, "D", "name", "d1");
Vertex d2 = this.sqlgGraph.addVertex(T.label, "D", "name", "d2");
Vertex d3 = this.sqlgGraph.addVertex(T.label, "D", "name", "d3");
c1.addEdge("cd", d1);
c1.addEdge("cd", d2);
c1.addEdge("cd", d3);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V().hasLabel("A").emit().repeat(__.out("ab", "bc", "cd")).times(3).path();
Assert.assertEquals(4, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertEquals(14, paths.size());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a1) && ((Vertex) p.get(0)).value("name.AA").equals("a1")));
paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(a1)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b2)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b2)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b3)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b3)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1)));
paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1)));
paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c2)));
paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c2)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c3)));
paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c3)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d1)));
paths.remove(paths.stream().filter(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d1)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d1)));
paths.remove(paths.stream().filter(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d1)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d2)));
paths.remove(paths.stream().filter(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d2)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d2)));
paths.remove(paths.stream().filter(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d2)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d3)));
paths.remove(paths.stream().filter(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d3)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d3)));
paths.remove(paths.stream().filter(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d3)).findAny().get());
Assert.assertTrue(paths.isEmpty());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testTimesBeforeAfterFirstNoEmit.
@Test
public void testTimesBeforeAfterFirstNoEmit() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
Vertex d1 = this.sqlgGraph.addVertex(T.label, "D", "name", "d1");
a1.addEdge("ab", b1);
b1.addEdge("bc", c1);
c1.addEdge("cd", d1);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V().hasLabel("A").times(3).repeat(__.out()).path();
Assert.assertEquals(4, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertEquals(1, paths.size());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(d1)));
DefaultGraphTraversal<Vertex, Path> traversal1 = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V().hasLabel("A").repeat(__.out()).times(4).path();
Assert.assertEquals(4, traversal1.getSteps().size());
paths = traversal1.toList();
Assert.assertEquals(2, traversal1.getSteps().size());
Assert.assertEquals(0, paths.size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testRepeatWithUnoptimizableInternalSteps.
@Test
public // This is not optimized
void testRepeatWithUnoptimizableInternalSteps() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "c2");
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "c3");
b1.addEdge("bc", c1);
b1.addEdge("bc", c2);
b1.addEdge("bc", c3);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Map<String, Vertex>> traversal = (DefaultGraphTraversal<Vertex, Map<String, Vertex>>) this.sqlgGraph.traversal().V().repeat(__.groupCount("m").by("name").out()).times(2).<Map<String, Vertex>>cap("m");
Assert.assertEquals(3, traversal.getSteps().size());
List<Map<String, Vertex>> t = traversal.toList();
Assert.assertEquals(3, traversal.getSteps().size());
Assert.assertEquals(1, t.size());
Assert.assertTrue(t.get(0).containsKey("a1"));
Assert.assertTrue(t.get(0).containsKey("b1"));
Assert.assertTrue(t.get(0).containsKey("b1"));
Assert.assertTrue(t.get(0).containsKey("b1"));
Assert.assertTrue(t.get(0).containsKey("c1"));
Assert.assertTrue(t.get(0).containsKey("c1"));
Assert.assertTrue(t.get(0).containsKey("c1"));
Assert.assertEquals(1L, t.get(0).get("a1"));
Assert.assertEquals(2L, t.get(0).get("b1"));
Assert.assertEquals(2L, t.get(0).get("b2"));
Assert.assertEquals(2L, t.get(0).get("b3"));
Assert.assertEquals(2L, t.get(0).get("c1"));
Assert.assertEquals(2L, t.get(0).get("c2"));
Assert.assertEquals(2L, t.get(0).get("c3"));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testRepeatSimpleTimeEmitAfter.
@Test
public void testRepeatSimpleTimeEmitAfter() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
a1.addEdge("ab", b1);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V(a1).repeat(__.out()).times(1).emit().path();
Assert.assertEquals(3, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertEquals(1, paths.size());
List<Predicate<Path>> pathsToAssert = Arrays.asList(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1));
for (Predicate<Path> pathPredicate : pathsToAssert) {
Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
Assert.assertTrue(path.isPresent());
Assert.assertTrue(paths.remove(path.get()));
}
Assert.assertTrue(paths.isEmpty());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testGremlinLeftJoin.
@Test
public void testGremlinLeftJoin() {
Vertex marko = this.sqlgGraph.addVertex(T.label, "Person", "name", "marko");
Vertex josh = this.sqlgGraph.addVertex(T.label, "Person", "name", "josh");
Vertex lop = this.sqlgGraph.addVertex(T.label, "Software", "name", "lop");
marko.addEdge("knows", josh);
marko.addEdge("created", lop);
josh.addEdge("created", lop);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V().repeat(__.out()).times(2).emit().path();
Assert.assertEquals(3, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertEquals(4, paths.size());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(marko) && p.get(1).equals(lop)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(marko) && p.get(1).equals(lop)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(josh) && p.get(1).equals(lop)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(josh) && p.get(1).equals(lop)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(marko) && p.get(1).equals(josh)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(marko) && p.get(1).equals(josh)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(marko) && p.get(1).equals(josh) && p.get(2).equals(lop)));
paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(marko) && p.get(1).equals(josh) && p.get(2).equals(lop)).findAny().get());
Assert.assertTrue(paths.isEmpty());
DefaultGraphTraversal<Vertex, Vertex> traversal1 = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().repeat(__.out()).times(2).emit();
Assert.assertEquals(2, traversal1.getSteps().size());
List<Vertex> vertices = traversal1.toList();
Assert.assertEquals(1, traversal1.getSteps().size());
Assert.assertEquals(4, vertices.size());
Assert.assertTrue(vertices.remove(josh));
Assert.assertTrue(vertices.remove(lop));
Assert.assertTrue(vertices.remove(lop));
Assert.assertTrue(vertices.remove(lop));
Assert.assertTrue(vertices.isEmpty());
}
Aggregations