Search in sources :

Example 1 with SqlgRepeatStepBarrier

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));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) SqlgRepeatStepBarrier(org.umlg.sqlg.step.barrier.SqlgRepeatStepBarrier) RepeatStep(org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep) RangeGlobalStep(org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 2 with SqlgRepeatStepBarrier

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());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) SqlgRepeatStepBarrier(org.umlg.sqlg.step.barrier.SqlgRepeatStepBarrier) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) SqlgVertexStep(org.umlg.sqlg.step.SqlgVertexStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)2 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)2 Test (org.junit.Test)2 SqlgRepeatStepBarrier (org.umlg.sqlg.step.barrier.SqlgRepeatStepBarrier)2 BaseTest (org.umlg.sqlg.test.BaseTest)2 RepeatStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.RepeatStep)1 RangeGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.filter.RangeGlobalStep)1 SqlgGraphStep (org.umlg.sqlg.step.SqlgGraphStep)1 SqlgVertexStep (org.umlg.sqlg.step.SqlgVertexStep)1