Search in sources :

Example 46 with SqlgGraphStep

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

the class TestHasLabelAndId method testConsecutiveEqHasWithoutIdAndLabels.

@Test
public void testConsecutiveEqHasWithoutIdAndLabels() {
    Vertex a = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b = this.sqlgGraph.addVertex(T.label, "B");
    Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
    Vertex c = this.sqlgGraph.addVertex(T.label, "C");
    Vertex d = this.sqlgGraph.addVertex(T.label, "D");
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A", "B", "C", "D").has(T.id, P.without(b.id(), b2.id()));
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(3, vertices.size());
    Assert.assertTrue(vertices.contains(a) && vertices.contains(c) && vertices.contains(d));
    Assert.assertEquals(1, traversal.getSteps().size());
    Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
    SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
    Assert.assertEquals(1, sqlgGraphStep.getReplacedSteps().size());
    ReplacedStep replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(0);
    // without's labels are merged into the previous labelHasContainers
    // this is because without has 'or' logic rather than 'and'
    Assert.assertEquals(1, replacedStep.getLabelHasContainers().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) ReplacedStep(org.umlg.sqlg.sql.parse.ReplacedStep) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 47 with SqlgGraphStep

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

the class TestHasLabelAndId method testInWithHasLabelAndHasWithoutId2.

@Test
public void testInWithHasLabelAndHasWithoutId2() {
    Vertex a = this.sqlgGraph.addVertex(T.label, "A");
    Vertex b = this.sqlgGraph.addVertex(T.label, "B");
    Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
    Vertex c = this.sqlgGraph.addVertex(T.label, "C");
    Vertex d = this.sqlgGraph.addVertex(T.label, "D");
    b.addEdge("ab", a);
    b2.addEdge("ab", a);
    c.addEdge("ac", a);
    d.addEdge("ad", a);
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").in().hasLabel("B", "C", "D").has(T.id, P.without(b.id(), c.id()));
    List<Vertex> vertices = traversal.toList();
    Assert.assertEquals(2, vertices.size());
    Assert.assertTrue(vertices.contains(b2) && vertices.contains(d));
    Assert.assertEquals(1, traversal.getSteps().size());
    Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
    SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
    Assert.assertEquals(2, sqlgGraphStep.getReplacedSteps().size());
    ReplacedStep replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(0);
    Assert.assertEquals(1, replacedStep.getLabelHasContainers().size());
    replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(1);
    Assert.assertEquals(1, replacedStep.getLabelHasContainers().size());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) ReplacedStep(org.umlg.sqlg.sql.parse.ReplacedStep) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 48 with SqlgGraphStep

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

the class TestPathStep method g_V_asXaX_hasXname_markoX_asXbX_hasXage_29X_asXcX_path.

@Test
public void g_V_asXaX_hasXname_markoX_asXbX_hasXage_29X_asXcX_path() throws IOException {
    Graph graph = this.sqlgGraph;
    loadModern(this.sqlgGraph);
    assertModernGraph(graph, true, false);
    GraphTraversalSource g = graph.traversal();
    DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) g.V().as("a").has("name", "marko").as("b").has("age", 29).as("c").path();
    Assert.assertEquals(3, traversal.getSteps().size());
    printTraversalForm(traversal);
    Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
    Assert.assertEquals(3, traversal.getSteps().size());
    final Path path = traversal.next();
    Assert.assertFalse(traversal.hasNext());
    Assert.assertEquals(1, path.size());
    Assert.assertTrue(path.hasLabel("a"));
    Assert.assertTrue(path.hasLabel("b"));
    Assert.assertTrue(path.hasLabel("c"));
    Assert.assertEquals(1, path.labels().size());
    Assert.assertEquals(3, path.labels().get(0).size());
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) Path(org.apache.tinkerpop.gremlin.process.traversal.Path) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) Graph(org.apache.tinkerpop.gremlin.structure.Graph) SqlgGraphStep(org.umlg.sqlg.step.SqlgGraphStep) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 49 with SqlgGraphStep

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

the class TestRangeLimit method testRangeOnVertexLabelsNoOrder.

@Test
public void testRangeOnVertexLabelsNoOrder() {
    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").range(1, 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);
        assertStep(sqlgGraphStep, true, false, false, true, true);
    }
    while (g.hasNext()) {
        String n = (String) g.next();
        names.add(n);
        cnt++;
    }
    ensureNoRangeGlobal(g);
    Assert.assertEquals(3, cnt);
    Assert.assertEquals(names.toString(), 3, 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)

Example 50 with SqlgGraphStep

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

the class TestRangeLimit method testRangeOnEdgeLabels.

@Test
public void testRangeOnEdgeLabels() {
    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<Edge, Object> g = (DefaultGraphTraversal<Edge, Object>) this.sqlgGraph.traversal().E().hasLabel("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("e1"));
    Assert.assertTrue(names.toString(), names.contains("e10"));
    Assert.assertTrue(names.toString(), names.contains("e11"));
}
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) Edge(org.apache.tinkerpop.gremlin.structure.Edge) 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