use of org.umlg.sqlg.step.barrier.SqlgRepeatStepBarrier in project sqlg by pietermartin.
the class TestUnoptimizedRepeatStep method testRepeatStepWithLimit.
@Test
public void testRepeatStepWithLimit() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
a1.addEdge("ab", b1);
a2.addEdge("ab", b2);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").until(__.has(T.label, "B")).repeat(__.out()).limit(1);
Assert.assertEquals(4, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(2) instanceof RepeatStep);
Assert.assertTrue(traversal.getSteps().get(3) instanceof RangeGlobalStep);
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(1) instanceof SqlgRepeatStepBarrier);
Assert.assertEquals(1, vertices.size());
Assert.assertTrue(vertices.contains(b1) || vertices.contains(b2));
vertices = this.sqlgGraph.traversal().V().hasLabel("A").repeat(__.out()).until(__.has(T.label, "B")).limit(1).toList();
Assert.assertEquals(1, vertices.size());
Assert.assertTrue(vertices.contains(b1) || vertices.contains(b2));
}
use of org.umlg.sqlg.step.barrier.SqlgRepeatStepBarrier in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testRepeatToSelf.
@Test
public void testRepeatToSelf() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
a1.addEdge("aa", a2);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().repeat(__.out()).until(__.hasLabel("A"));
Assert.assertEquals(2, traversal.getSteps().size());
printTraversalForm(traversal);
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
Assert.assertTrue(traversal.getSteps().get(1) instanceof SqlgRepeatStepBarrier);
SqlgRepeatStepBarrier repeatStep = (SqlgRepeatStepBarrier) traversal.getSteps().get(1);
DefaultGraphTraversal traversal1 = (DefaultGraphTraversal) repeatStep.getGlobalChildren().get(0);
Assert.assertEquals(2, traversal1.getSteps().size());
Assert.assertTrue(traversal1.getSteps().get(0) instanceof SqlgVertexStep);
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(1, vertices.size());
}
Aggregations