Search in sources :

Example 6 with SqlgGraphStep

use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.

the class TestRangeLimit method testRange.

@Test
public void testRange() {
    Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
    for (int i = 0; i < 10; i++) {
        Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i);
        a.addEdge("ab", b);
    }
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").out().range(5, 6);
    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, false, true, true);
    Assert.assertEquals(1, 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 7 with SqlgGraphStep

use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.

the class TestRangeLimit method testRangeOnMultipleLabelsOrderedWithSkip.

@Test
public void testRangeOnMultipleLabelsOrderedWithSkip() {
    Vertex c = this.sqlgGraph.addVertex(T.label, "C", "name", "c" + 12);
    for (int i = 0; i < 20; i++) {
        Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i);
        Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i);
        a.addEdge("E", b, "name", "e" + i);
    }
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>) this.sqlgGraph.traversal().V().hasLabel("A", "B").order().by("name").skip(2).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, true, true, true, false);
    }
    while (g.hasNext()) {
        String n = (String) g.next();
        names.add(n);
        if (previous != null) {
            Assert.assertTrue(previous.compareTo(n) < 0);
        }
        previous = n;
        cnt++;
    }
    // order by on multiple labels is not done in SQL, so the range isn't
    // ensureRangeGlobal(g);
    Assert.assertEquals(38, cnt);
    Assert.assertEquals(names.toString(), 38, names.size());
    Assert.assertTrue(names.toString(), !names.contains("a0"));
    Assert.assertTrue(names.toString(), !names.contains("a1"));
}
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 8 with SqlgGraphStep

use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.

the class TestRangeLimit method testRangeOnEdgesOutput.

@Test
public void testRangeOnEdgesOutput() {
    Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a0");
    for (int i = 0; i < 20; i++) {
        Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i);
        a.addEdge("E", b, "name", "e" + i);
    }
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>) this.sqlgGraph.traversal().V(a).out("E").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("b1"));
    Assert.assertTrue(names.toString(), names.contains("b10"));
    Assert.assertTrue(names.toString(), names.contains("b11"));
}
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 9 with SqlgGraphStep

use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.

the class TestRangeLimit method testLimitOnVertexLabels.

@Test
public void testLimitOnVertexLabels() {
    for (int i = 0; i < 20; i++) {
        this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i);
    }
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>) this.sqlgGraph.traversal().V().hasLabel("A").order().by("name").limit(3).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("a0"));
}
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 10 with SqlgGraphStep

use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.

the class TestRangeLimit method testRangeOnMultipleLabels.

@Test
public void testRangeOnMultipleLabels() {
    for (int i = 0; i < 20; i++) {
        Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i);
        Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i);
        a.addEdge("E", b, "name", "e" + i);
    }
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>) this.sqlgGraph.traversal().V().hasLabel("A", "B").limit(4).values("name");
    Assert.assertEquals(4, g.getSteps().size());
    ensureRangeGlobal(g);
    int cnt = 0;
    Set<String> names = new HashSet<>();
    if (g.hasNext()) {
        Assert.assertEquals(2, g.getSteps().size());
        Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep);
        SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0);
        // TODO this really should execute limit on the db and finally in the step.
        // That way less results are returned from the db
        assertStep(sqlgGraphStep, true, false, true, true, false);
    }
    while (g.hasNext()) {
        String n = (String) g.next();
        names.add(n);
        cnt++;
    }
    // we still have to cut the union result
    // ensureRangeGlobal(g);
    Assert.assertEquals(4, cnt);
    Assert.assertEquals(names.toString(), 4, names.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) HashSet(java.util.HashSet) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Aggregations

SqlgGraphStep (org.umlg.sqlg.step.SqlgGraphStep)59 DefaultGraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal)57 Vertex (org.apache.tinkerpop.gremlin.structure.Vertex)57 Test (org.junit.Test)57 BaseTest (org.umlg.sqlg.test.BaseTest)57 ReplacedStep (org.umlg.sqlg.sql.parse.ReplacedStep)31 HashSet (java.util.HashSet)10 SqlgVertexStep (org.umlg.sqlg.step.SqlgVertexStep)6 Path (org.apache.tinkerpop.gremlin.process.traversal.Path)3 Traversal (org.apache.tinkerpop.gremlin.process.traversal.Traversal)3 GraphTraversalSource (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource)3 SqlgLocalStepBarrier (org.umlg.sqlg.step.barrier.SqlgLocalStepBarrier)3 List (java.util.List)2 Map (java.util.Map)2 Collectors (java.util.stream.Collectors)2 StopWatch (org.apache.commons.lang3.time.StopWatch)2 Step (org.apache.tinkerpop.gremlin.process.traversal.Step)2 GraphTraversal (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversal)2 org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__ (org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.__)2 OrderGlobalStep (org.apache.tinkerpop.gremlin.process.traversal.step.map.OrderGlobalStep)2