Search in sources :

Example 56 with DefaultGraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.

the class TestRangeLimit method testRangeOnVertexLabelsCriteria.

@Test
public void testRangeOnVertexLabelsCriteria() {
    for (int i = 0; i < 100; i++) {
        this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i, "prop0", "value");
    }
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>) this.sqlgGraph.traversal().V().hasLabel("A").has("prop0", "value").order().by("name").range(1, 4).values("name");
    Assert.assertEquals(5, g.getSteps().size());
    ensureRangeGlobal(g);
    int cnt = 0;
    Set<String> names = new HashSet<>();
    String previous = null;
    if (g.hasNext()) {
        Assert.assertEquals(2, g.getSteps().size());
        Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep);
        SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0);
        assertStep(sqlgGraphStep, true, false, false, false, true);
    }
    while (g.hasNext()) {
        String n = (String) g.next();
        names.add(n);
        if (previous != null) {
            Assert.assertTrue(previous.compareTo(n) < 0);
        }
        previous = n;
        cnt++;
    }
    ensureNoRangeGlobal(g);
    Assert.assertEquals(3, cnt);
    Assert.assertEquals(names.toString(), 3, names.size());
    Assert.assertTrue(names.toString(), names.contains("a1"));
    Assert.assertTrue(names.toString(), names.contains("a10"));
    Assert.assertTrue(names.toString(), names.contains("a11"));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) HashSet(java.util.HashSet) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 57 with DefaultGraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.

the class TestRangeLimit method testSkipAfterNonOptimizedStep.

@Test
public void testSkipAfterNonOptimizedStep() {
    for (int i = 0; i < 100; i++) {
        Vertex column = this.sqlgGraph.addVertex(T.label, "BigData.Column");
        Vertex tag = this.sqlgGraph.addVertex(T.label, "BigData.Tag", "name", "NonAnonymized");
        tag.addEdge("tag", column);
    }
    for (int i = 0; i < 100; i++) {
        Vertex column = this.sqlgGraph.addVertex(T.label, "BigData.Column");
        Vertex tag = this.sqlgGraph.addVertex(T.label, "BigData.Tag", "name", "Anonymized");
        tag.addEdge("tag", column);
    }
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("BigData.Column").where(__.in("tag").hasLabel("BigData.Tag").has("name", "Anonymized")).skip(2);
    Assert.assertEquals(4, traversal.getSteps().size());
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(3, traversal.getSteps().size());
    Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
    SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
    assertStep(sqlgGraphStep, true, false, false, true, true);
    Assert.assertEquals(98, vertices.size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 58 with DefaultGraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.

the class TestRangeLimit method testRangeWithNoOrder.

@Test
public void testRangeWithNoOrder() {
    for (int i = 0; i < 100; i++) {
        Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "age", i);
        Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "age", i);
        Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "age", i);
        a1.addEdge("ab", b1);
        b1.addEdge("bc", c1);
    }
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("B").both().limit(10);
    Assert.assertEquals(4, traversal.getSteps().size());
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(1, traversal.getSteps().size());
    Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
    SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
    assertStep(sqlgGraphStep, true, false, true, true, false);
    Assert.assertEquals(10, vertices.size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 59 with DefaultGraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.

the class TestRepeatStepGraphBoth method testRepeatBoth2.

@Test
public void testRepeatBoth2() {
    Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
    Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
    Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
    a1.addEdge("ab", b1);
    b1.addEdge("bc", c1);
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V(b1).repeat(__.both()).times(3);
    Assert.assertEquals(2, traversal.getSteps().size());
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(1, traversal.getSteps().size());
    Assert.assertEquals(4, vertices.size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 60 with DefaultGraphTraversal

use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.

the class TestRepeatStepGraphBoth method testRepeatAndOut.

@Test
public void testRepeatAndOut() {
    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, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().repeat(__.both()).times(1).out();
    Assert.assertEquals(3, traversal.getSteps().size());
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(1, traversal.getSteps().size());
    Assert.assertEquals(1, vertices.size());
    Assert.assertEquals(b1, vertices.get(0));
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)270 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)260 Test (org.junit.Test)251 BaseTest (org.umlg.sqlg.test.BaseTest)251 SqlgGraphStep (org.umlg.sqlg.step.SqlgGraphStep)80 Path (org.apache.tinkerpop.gremlin.process.traversal.Path)78 T (org.apache.tinkerpop.gremlin.structure.T)56 Assert (org.junit.Assert)56 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)55 Graph (org.apache.tinkerpop.gremlin.structure.Graph)49 SqlgVertexStep (org.umlg.sqlg.step.SqlgVertexStep)43 List (java.util.List)35 Predicate (java.util.function.Predicate)35 Map (java.util.Map)31 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)31 Edge (org.apache.tinkerpop.gremlin.structure.Edge)30 ReplacedStep (org.umlg.sqlg.sql.parse.ReplacedStep)29 SqlgVertex (org.umlg.sqlg.structure.SqlgVertex)24 java.util (java.util)23 IOException (java.io.IOException)22