Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal#getSteps()

The following examples show how to use org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal#getSteps() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestNotStepBarrier.java    From sqlg with MIT License 6 votes vote down vote up
@Test
public void testNotStepBarrier() {
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
    Vertex a2 = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
    a1.addEdge("ab", b1);
    this.sqlgGraph.tx().commit();

    DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").not(__.out());
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(1, vertices.size());
    Assert.assertEquals(a2, vertices.get(0));
    List<Step> steps = traversal.getSteps();
    Assert.assertEquals(2, steps.size());
    Assert.assertTrue(steps.get(1) instanceof SqlgNotStepBarrier);
    SqlgNotStepBarrier sqlgNotStepBarrier = (SqlgNotStepBarrier) steps.get(1);
    Assert.assertEquals(1, sqlgNotStepBarrier.getLocalChildren().size());
    Traversal.Admin t = (Traversal.Admin) sqlgNotStepBarrier.getLocalChildren().get(0);
    Assert.assertEquals(1, t.getSteps().size());
    Assert.assertTrue(t.getSteps().get(0) instanceof SqlgVertexStep);
}
 
Example 2
Source File: TestRangeLimit.java    From sqlg with MIT License 5 votes vote down vote up
/**
 * ensure once we've built the traversal, it contains a RangeGlobalStep
 *
 * @param g
 */
private void ensureRangeGlobal(GraphTraversal<?, ?> g) {
    DefaultGraphTraversal<?, ?> dgt = (DefaultGraphTraversal<?, ?>) g;
    boolean found = false;
    for (Step<?, ?> s : dgt.getSteps()) {
        found |= (s instanceof RangeGlobalStep<?>);
    }
    Assert.assertTrue(found);
}
 
Example 3
Source File: TestRangeLimit.java    From sqlg with MIT License 5 votes vote down vote up
/**
 * once we've run the traversal, it shouldn't contain the RangeGlobalStep,
 * since it was changed into a Range on the ReplacedStep
 *
 * @param g
 */
private void ensureNoRangeGlobal(GraphTraversal<?, ?> g) {
    DefaultGraphTraversal<?, ?> dgt = (DefaultGraphTraversal<?, ?>) g;
    for (Step<?, ?> s : dgt.getSteps()) {
        Assert.assertFalse(s instanceof RangeGlobalStep<?>);
    }
}
 
Example 4
Source File: TestOrStepAfterVertexStepBarrier.java    From sqlg with MIT License 5 votes vote down vote up
@Test
public void testOrStepAfterVertexStepBarrier() {
    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);
    this.sqlgGraph.tx().commit();

    DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A")
            .local(
                    __.out().or(
                            __.has("name", "b2"),
                            __.has("name", "b3")
                    )
            );
    List<Vertex> vertices = traversal.toList();
    List<Step> steps = traversal.getSteps();
    Assert.assertEquals(2, steps.size());
    Assert.assertTrue(steps.get(1) instanceof SqlgLocalStepBarrier);
    SqlgLocalStepBarrier sqlgLocalStepBarrier = (SqlgLocalStepBarrier)steps.get(1);
    Assert.assertEquals(1, sqlgLocalStepBarrier.getLocalChildren().size());
    Traversal.Admin t = (Traversal.Admin) sqlgLocalStepBarrier.getLocalChildren().get(0);
    //or step is collapsed into the vertex step.
    Assert.assertEquals(1, t.getSteps().size());
    Assert.assertEquals(2, vertices.size());
}
 
Example 5
Source File: MidTraversalGraphTest.java    From sqlg with MIT License 5 votes vote down vote up
/**
 * ensure once we've built the traversal, it contains a RangeGlobalStep
 *
 * @param g
 */
private void ensureCompiledGraphStep(GraphTraversal<?, ?> g, int expectedCount) {
    DefaultGraphTraversal<?, ?> dgt = (DefaultGraphTraversal<?, ?>) g;
    int count = 0;
    for (Step<?, ?> s : dgt.getSteps()) {
        if (s.getClass().getSimpleName().equals("SqlgGraphStep")) {
            count++;
        }
    }
    assertEquals(expectedCount, count);
}