use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testRepeat.
@Test
public void testRepeat() {
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, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").times(0).repeat(__.out("ab").out("bc"));
Assert.assertEquals(3, traversal.getSteps().size());
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertEquals(1, vertices.size());
Assert.assertTrue(vertices.contains(a1));
DefaultGraphTraversal<Vertex, Vertex> traversal1 = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").repeat(__.out("ab", "bc")).times(1);
Assert.assertEquals(3, traversal1.getSteps().size());
vertices = traversal1.toList();
Assert.assertEquals(1, traversal1.getSteps().size());
Assert.assertEquals(3, vertices.size());
Assert.assertTrue(vertices.contains(b1));
Assert.assertTrue(vertices.contains(b2));
Assert.assertTrue(vertices.contains(b3));
DefaultGraphTraversal<Vertex, Vertex> traversal2 = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").times(1).repeat(__.out("ab", "bc"));
Assert.assertEquals(3, traversal2.getSteps().size());
vertices = traversal2.toList();
Assert.assertEquals(1, traversal2.getSteps().size());
Assert.assertEquals(3, vertices.size());
Assert.assertTrue(vertices.contains(b1));
Assert.assertTrue(vertices.contains(b2));
Assert.assertTrue(vertices.contains(b3));
DefaultGraphTraversal<Vertex, Vertex> traversal3 = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").repeat(__.out("ab", "bc")).times(2);
Assert.assertEquals(3, traversal3.getSteps().size());
vertices = traversal3.toList();
Assert.assertEquals(1, traversal3.getSteps().size());
Assert.assertEquals(3, vertices.size());
Assert.assertTrue(vertices.contains(c1));
Assert.assertTrue(vertices.contains(c2));
Assert.assertTrue(vertices.contains(c3));
DefaultGraphTraversal<Vertex, Vertex> traversal4 = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").times(2).repeat(__.out("ab", "bc"));
Assert.assertEquals(3, traversal4.getSteps().size());
vertices = traversal4.toList();
Assert.assertEquals(1, traversal4.getSteps().size());
Assert.assertEquals(3, vertices.size());
Assert.assertTrue(vertices.contains(c1));
Assert.assertTrue(vertices.contains(c2));
Assert.assertTrue(vertices.contains(c3));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method g_V_repeatXoutX_timesX2X.
@Test
public void g_V_repeatXoutX_timesX2X() throws IOException {
final List<DefaultGraphTraversal<Vertex, Vertex>> traversals = new ArrayList<>();
loadModern();
Graph graph = this.sqlgGraph;
assertModernGraph(graph, true, false);
DefaultGraphTraversal t = (DefaultGraphTraversal) graph.traversal().V().repeat(__.out()).times(2);
Assert.assertEquals(2, t.getSteps().size());
traversals.add(t);
traversals.forEach(traversal -> {
printTraversalForm(traversal);
Assert.assertEquals(1, traversal.getSteps().size());
int counter = 0;
while (traversal.hasNext()) {
counter++;
Vertex vertex = traversal.next();
Assert.assertTrue(vertex.value("name").equals("lop") || vertex.value("name").equals("ripple"));
}
Assert.assertEquals(2, counter);
Assert.assertFalse(traversal.hasNext());
});
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testRepeatWithTimesBefore.
@Test
public void testRepeatWithTimesBefore() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
a1.addEdge("ab", b1);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V().emit().times(2).repeat(__.out()).path();
Assert.assertEquals(3, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertEquals(3, paths.size());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).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() == 1 && p.get(0).equals(b1)));
paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(b1)).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 testTimesBeforeEmitBeforeToSelf.
@Test
public void testTimesBeforeEmitBeforeToSelf() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A");
a1.addEdge("aa", a2);
a1.addEdge("ab", b1);
a2.addEdge("aa", a3);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V(a1).emit().times(2).repeat(__.out()).path();
Assert.assertEquals(3, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
for (Path path : paths) {
System.out.println(path);
}
List<Predicate<Path>> pathsToAssert = Arrays.asList(p -> p.size() == 1 && p.get(0).equals(a1), p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1), p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(a2), p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(a2) && p.get(2).equals(a3));
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 testOnLeftJoinOnLeaveNode.
@Test
public void testOnLeftJoinOnLeaveNode() {
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");
a1.addEdge("ab", b1);
a2.addEdge("ab", b1);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").emit().repeat(__.out("ab")).times(1);
Assert.assertEquals(3, traversal.getSteps().size());
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertEquals(4, vertices.size());
}
Aggregations