Search in sources :

Example 16 with SqlgLocalStepBarrier

use of org.umlg.sqlg.step.barrier.SqlgLocalStepBarrier in project sqlg by pietermartin.

the class TestLocalVertexStepOptional method testOptional.

@Test
public void testOptional() {
    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");
    a1.addEdge("ab", b1);
    a1.addEdge("ab", b2);
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V(a1).local(__.optional(__.out()).path());
    List<Path> paths = traversal.toList();
    Assert.assertEquals(2, traversal.getSteps().size());
    Assert.assertTrue(traversal.getSteps().get(1) instanceof SqlgLocalStepBarrier);
    SqlgLocalStepBarrier<?, ?> localStep = (SqlgLocalStepBarrier) traversal.getSteps().get(1);
    List<SqlgVertexStep> sqlgVertexStepCompileds = TraversalHelper.getStepsOfAssignableClassRecursively(SqlgVertexStep.class, localStep.getLocalChildren().get(0));
    Assert.assertEquals(1, sqlgVertexStepCompileds.size());
    SqlgVertexStep sqlgVertexStepCompiled = sqlgVertexStepCompileds.get(0);
    // isForMultipleQueries is arbitary
    assertStep(sqlgVertexStepCompiled, false, false, true, true);
    Assert.assertEquals(2, paths.size());
    List<Predicate<Path>> pathsToAssert = Arrays.asList(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(b2));
    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());
}
Also used : Path(org.apache.tinkerpop.gremlin.process.traversal.Path) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Predicate(java.util.function.Predicate) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) SqlgLocalStepBarrier(org.umlg.sqlg.step.barrier.SqlgLocalStepBarrier) 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)16 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)16 Test (org.junit.Test)16 SqlgLocalStepBarrier (org.umlg.sqlg.step.barrier.SqlgLocalStepBarrier)16 BaseTest (org.umlg.sqlg.test.BaseTest)16 SqlgVertexStep (org.umlg.sqlg.step.SqlgVertexStep)14 Path (org.apache.tinkerpop.gremlin.process.traversal.Path)9 Predicate (java.util.function.Predicate)5 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)5 LocalStep (org.apache.tinkerpop.gremlin.process.traversal.step.branch.LocalStep)4 SqlgGraphStep (org.umlg.sqlg.step.SqlgGraphStep)4 SqlgOptionalStepBarrier (org.umlg.sqlg.step.barrier.SqlgOptionalStepBarrier)4 List (java.util.List)3 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)3 OrderGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep)3 IdentityStep (org.apache.tinkerpop.gremlin.process.traversal.step.sideEffect.IdentityStep)3 TraversalHelper (org.apache.tinkerpop.gremlin.process.traversal.util.TraversalHelper)3 Element (org.apache.tinkerpop.gremlin.structure.Element)3 T (org.apache.tinkerpop.gremlin.structure.T)3 Assert (org.junit.Assert)3