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"));
});
}
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));
}
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());
}
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);
}
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());
}
Aggregations