Search in sources :

Example 91 with DefaultGraphTraversal

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

the class TestTreeStep method g_VX1X_out_out_tree_byXnameX.

@Test
public void g_VX1X_out_out_tree_byXnameX() throws IOException {
    Graph graph = this.sqlgGraph;
    loadModern(this.sqlgGraph);
    assertModernGraph(graph, true, false);
    GraphTraversalSource g = this.sqlgGraph.traversal();
    final List<DefaultGraphTraversal<Vertex, Tree>> traversals = Arrays.asList((DefaultGraphTraversal) g.V(convertToVertexId("marko")).out().out().tree().by("name"), (DefaultGraphTraversal) g.V(convertToVertexId("marko")).out().out().tree("a").by("name").both().both().cap("a"));
    traversals.forEach(traversal -> {
        printTraversalForm(traversal);
        final Tree tree = traversal.next();
        Assert.assertFalse(traversal.hasNext());
        Assert.assertEquals(1, tree.size());
        Assert.assertTrue(tree.containsKey("marko"));
        Assert.assertEquals(1, ((Map) tree.get("marko")).size());
        Assert.assertTrue(((Map) tree.get("marko")).containsKey("josh"));
        Assert.assertTrue(((Map) ((Map) tree.get("marko")).get("josh")).containsKey("lop"));
        Assert.assertTrue(((Map) ((Map) tree.get("marko")).get("josh")).containsKey("ripple"));
    });
}
Also used : GraphTraversalSource(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.GraphTraversalSource) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) Graph(org.apache.tinkerpop.gremlin.structure.Graph) Tree(org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree) Map(java.util.Map) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 92 with DefaultGraphTraversal

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

the class TestTreeStep method testTreeWithSideEffect.

@Test
public void testTreeWithSideEffect() {
    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);
    Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
    Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "c2");
    Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "c3");
    b1.addEdge("bc", c1);
    b1.addEdge("bc", c2);
    b1.addEdge("bc", c3);
    DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").out().out().tree("a");
    Assert.assertEquals(5, traversal.getSteps().size());
    Vertex v = traversal.next();
    Assert.assertEquals(2, traversal.getSteps().size());
    Assert.assertTrue(Matchers.isOneOf(c1, c2, c3).matches(v));
}
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 93 with DefaultGraphTraversal

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

the class TestTreeStep method testTree.

@Test
public void testTree() {
    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);
    Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
    Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "c2");
    Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "c3");
    b1.addEdge("bc", c1);
    b1.addEdge("bc", c2);
    b1.addEdge("bc", c3);
    this.sqlgGraph.tx().commit();
    DefaultGraphTraversal<Vertex, Tree> traversal = (DefaultGraphTraversal<Vertex, Tree>) this.sqlgGraph.traversal().V().hasLabel("A").out().out().tree();
    Assert.assertEquals(5, traversal.getSteps().size());
    Tree tree = traversal.next();
    Assert.assertEquals(2, traversal.getSteps().size());
    Assert.assertEquals(1, tree.size());
    Assert.assertTrue(tree.containsKey(a1));
    Tree tree2 = (Tree) tree.get(a1);
    Assert.assertEquals(1, tree2.size());
    Assert.assertTrue(tree2.containsKey(b1));
    Tree tree3 = (Tree) tree2.get(b1);
    Assert.assertEquals(3, tree3.size());
    Assert.assertTrue(tree3.containsKey(c1));
    Assert.assertTrue(tree3.containsKey(c1));
    Assert.assertTrue(tree3.containsKey(c1));
// left join todo
// GraphTraversal gt = this.sqlgGraph.traversal().V().hasLabel("A").emit().repeat(__.out("ab", "bc")).times(2).tree();
// System.out.println(gt.toString());
// System.out.println(gt.next());
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) Tree(org.apache.tinkerpop.gremlin.process.traversal.step.util.Tree) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 94 with DefaultGraphTraversal

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

the class TestMatch method testMatch2.

@Test
public void testMatch2() {
    loadModern();
    Vertex marko = convertToVertex(this.sqlgGraph, "marko");
    DefaultGraphTraversal<Vertex, Map<String, Object>> traversal = (DefaultGraphTraversal<Vertex, Map<String, Object>>) this.sqlgGraph.traversal().V(marko).match(__.as("a").out("knows").as("b"), __.as("a").out("created").as("c"));
    // List<Map<String, Object>> result = traversal.toList();
    checkResults(makeMapList(3, "a", convertToVertex(this.sqlgGraph, "marko"), "b", convertToVertex(this.sqlgGraph, "vadas"), "c", convertToVertex(this.sqlgGraph, "lop"), "a", convertToVertex(this.sqlgGraph, "marko"), "b", convertToVertex(this.sqlgGraph, "josh"), "c", convertToVertex(this.sqlgGraph, "lop")), traversal);
}
Also used : Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) Map(java.util.Map) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test)

Example 95 with DefaultGraphTraversal

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

the class TestGremlinCompileWithAs method testHasLabelOutWithAs_assert.

private void testHasLabelOutWithAs_assert(SqlgGraph sqlgGraph, Vertex a1, Vertex b1, Vertex b2, Vertex b3, Vertex b4, Edge e1, Edge e2, Edge e3, Edge e4) {
    DefaultGraphTraversal<Vertex, Map<String, Element>> traversal = (DefaultGraphTraversal) sqlgGraph.traversal().V(a1).outE("outB").as("e").inV().as("B").select("e", "B");
    Assert.assertEquals(4, traversal.getSteps().size());
    List<Map<String, Element>> result = traversal.toList();
    Assert.assertEquals(2, traversal.getSteps().size());
    Collections.sort(result, Comparator.comparing(o -> o.get("e").<String>value("edgeName")));
    Assert.assertEquals(4, result.size());
    Edge queryE0 = (Edge) result.get(0).get("e");
    Vertex queryB0 = (Vertex) result.get(0).get("B");
    Assert.assertEquals(e1, queryE0);
    Assert.assertEquals("b1", queryE0.inVertex().value("name"));
    Assert.assertEquals("a1", queryE0.outVertex().value("name"));
    Assert.assertEquals("edge1", queryE0.value("edgeName"));
    Assert.assertEquals(b1, queryB0);
    Assert.assertEquals("b1", queryB0.value("name"));
    Element queryE2 = result.get(1).get("e");
    Element queryB2 = result.get(1).get("B");
    Assert.assertEquals(e2, queryE2);
    Assert.assertEquals("edge2", queryE2.value("edgeName"));
    Assert.assertEquals(b2, queryB2);
    Assert.assertEquals("b2", queryB2.value("name"));
    Element queryE3 = result.get(2).get("e");
    Element queryB3 = result.get(2).get("B");
    Assert.assertEquals(e3, queryE3);
    Assert.assertEquals("edge3", queryE3.value("edgeName"));
    Assert.assertEquals(b3, queryB3);
    Assert.assertEquals("b3", queryB3.value("name"));
    Element queryE4 = result.get(3).get("e");
    Element queryB4 = result.get(3).get("B");
    Assert.assertEquals(e4, queryE4);
    Assert.assertEquals("edge4", queryE4.value("edgeName"));
    Assert.assertEquals(b4, queryB4);
    Assert.assertEquals("b4", queryB4.value("name"));
    DefaultGraphTraversal<Vertex, Edge> traversal1 = (DefaultGraphTraversal<Vertex, Edge>) sqlgGraph.traversal().V(a1.id()).bothE();
    Assert.assertEquals(2, traversal1.getSteps().size());
    final List<Edge> a1Edges = traversal1.toList();
    Assert.assertEquals(1, traversal1.getSteps().size());
    Assert.assertEquals(4, a1Edges.size());
    List<String> names = new ArrayList<>(Arrays.asList("b1", "b2", "b3", "b4"));
    for (Edge a1Edge : a1Edges) {
        names.remove(a1Edge.inVertex().<String>value("name"));
        Assert.assertEquals("a1", a1Edge.outVertex().<String>value("name"));
    }
    Assert.assertTrue(names.isEmpty());
}
Also used : java.util(java.util) BeforeClass(org.junit.BeforeClass) BaseTest(org.umlg.sqlg.test.BaseTest) Test(org.junit.Test) IOException(java.io.IOException) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) T(org.apache.tinkerpop.gremlin.structure.T) SqlgGraph(org.umlg.sqlg.structure.SqlgGraph) PropertyVetoException(java.beans.PropertyVetoException) Element(org.apache.tinkerpop.gremlin.structure.Element) Assert(org.junit.Assert) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) Edge(org.apache.tinkerpop.gremlin.structure.Edge) Vertex(org.apache.tinkerpop.gremlin.structure.Vertex) Element(org.apache.tinkerpop.gremlin.structure.Element) DefaultGraphTraversal(org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal) Edge(org.apache.tinkerpop.gremlin.structure.Edge)

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