use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestUnoptimizedRepeatStep method testRepeatStepPerformance.
// @Test
public void testRepeatStepPerformance() {
this.sqlgGraph.tx().normalBatchModeOn();
for (int i = 0; i < 1000; i++) {
Vertex a;
if (i % 100 == 0) {
a = this.sqlgGraph.addVertex(T.label, "A", "hubSite", true);
} else {
a = this.sqlgGraph.addVertex(T.label, "A", "hubSite", false);
}
for (int j = 0; j < 10; j++) {
Vertex b = this.sqlgGraph.addVertex(T.label, "A", "hubSite", false);
a.addEdge("link", b);
for (int k = 0; k < 10; k++) {
Vertex c;
if (k == 5) {
c = this.sqlgGraph.addVertex(T.label, "A", "hubSite", false);
} else {
c = this.sqlgGraph.addVertex(T.label, "A", "hubSite", false);
}
b.addEdge("link", c);
for (int l = 0; l < 10; l++) {
Vertex d = this.sqlgGraph.addVertex(T.label, "A", "hubSite", true);
c.addEdge("link", d);
}
}
}
}
this.sqlgGraph.tx().commit();
System.out.println("===========================");
StopWatch stopWatch = new StopWatch();
for (int i = 0; i < 1000; i++) {
stopWatch.start();
List<Path> vertices = this.sqlgGraph.traversal().V().has("hubSite", true).repeat(__.out()).until(__.or(__.loops().is(P.gt(3)), __.has("hubSite", true))).path().toList();
Assert.assertEquals(10000, vertices.size());
stopWatch.stop();
System.out.println(stopWatch.toString());
stopWatch.reset();
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestReplacedStepEmitComparator method testOrderFollowedByVertexStep.
@Test
public void testOrderFollowedByVertexStep() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a3");
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);
a2.addEdge("ab", b1);
a2.addEdge("ab", b2);
a2.addEdge("ab", b3);
a3.addEdge("ab", b1);
a3.addEdge("ab", b2);
a3.addEdge("ab", b3);
this.sqlgGraph.tx().commit();
List<Path> paths = this.sqlgGraph.traversal().V().hasLabel("A").order().by("name", Order.decr).out("ab").path().toList();
Assert.assertEquals(9, paths.size());
Assert.assertEquals(a3, paths.get(0).objects().get(0));
Assert.assertEquals(a3, paths.get(1).objects().get(0));
Assert.assertEquals(a3, paths.get(2).objects().get(0));
Assert.assertEquals(a2, paths.get(3).objects().get(0));
Assert.assertEquals(a2, paths.get(4).objects().get(0));
Assert.assertEquals(a2, paths.get(5).objects().get(0));
Assert.assertEquals(a1, paths.get(6).objects().get(0));
Assert.assertEquals(a1, paths.get(7).objects().get(0));
Assert.assertEquals(a1, paths.get(8).objects().get(0));
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestOutE method testOutEOrder.
@Test
public void testOutEOrder() throws Exception {
Vertex v1 = this.sqlgGraph.addVertex(T.label, "Person", "name", "p1");
Vertex v2 = this.sqlgGraph.addVertex(T.label, "Person", "name", "p2");
Vertex v3 = this.sqlgGraph.addVertex(T.label, "Person", "name", "p3");
Vertex v4 = this.sqlgGraph.addVertex(T.label, "Person", "name", "p4");
Vertex v5 = this.sqlgGraph.addVertex(T.label, "Person", "name", "p5");
v1.addEdge("e1", v2);
v2.addEdge("e2", v3);
v3.addEdge("e3", v4, "sequence", 1);
v3.addEdge("e3", v5, "sequence", 2);
this.sqlgGraph.tx().commit();
List<Path> ps = vertexTraversal(this.sqlgGraph, v1).out("e1").as("v2").out("e2").as("v3").outE("e3").order().by("sequence").inV().as("v4-5").path().toList();
assertEquals(2, ps.size());
assertEquals(v4, ps.get(0).get("v4-5"));
assertEquals(v5, ps.get(1).get("v4-5"));
ps = vertexTraversal(this.sqlgGraph, v1).out("e1").as("v2").out("e2").as("v3").outE("e3").order().by("sequence", Order.decr).inV().as("v4-5").path().toList();
assertEquals(2, ps.size());
assertEquals(v4, ps.get(1).get("v4-5"));
assertEquals(v5, ps.get(0).get("v4-5"));
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestAndStepBarrier method g_VX1X_repeatXboth_simplePathX_untilXhasXname_peterX_and_loops_isX3XX_hasXname_peterX_path_byXnameX.
@Test
public void g_VX1X_repeatXboth_simplePathX_untilXhasXname_peterX_and_loops_isX3XX_hasXname_peterX_path_byXnameX() {
loadModern();
final DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V(convertToVertexId("marko")).repeat(__.both().simplePath()).until(__.has("name", "peter").and().loops().is(3)).has("name", "peter").path().by("name");
printTraversalForm(traversal);
Assert.assertTrue(traversal.hasNext());
final Path path = traversal.next();
Assert.assertEquals(4, path.size());
Assert.assertEquals("marko", path.get(0));
Assert.assertEquals("josh", path.get(1));
Assert.assertEquals("lop", path.get(2));
Assert.assertEquals("peter", path.get(3));
Assert.assertFalse(traversal.hasNext());
List<SqlgAndStepBarrier> sqlgAndStepBarriers = TraversalHelper.getStepsOfAssignableClassRecursively(SqlgAndStepBarrier.class, traversal);
Assert.assertEquals(1, sqlgAndStepBarriers.size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestSqlgBranchStep method testSqlgBranchStepKeepsStartElementsOrder.
@Test
public void testSqlgBranchStepKeepsStartElementsOrder() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1", "order", 1);
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2", "order", 2);
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");
Vertex b4 = this.sqlgGraph.addVertex(T.label, "B", "name", "b4");
a1.addEdge("ab", b1, "order", 1);
a1.addEdge("ab", b2, "order", 2);
a1.addEdge("ab", b3, "order", 3);
a1.addEdge("ab", b4, "order", 0);
a2.addEdge("ab", b1, "order", 1);
a2.addEdge("ab", b2, "order", 2);
a2.addEdge("ab", b3, "order", 3);
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1", "order", 1);
Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "c2", "order", 2);
Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "c3", "order", 3);
Vertex c4 = this.sqlgGraph.addVertex(T.label, "C", "name", "c4", "order", 1);
Vertex c5 = this.sqlgGraph.addVertex(T.label, "C", "name", "c5", "order", 2);
Vertex c6 = this.sqlgGraph.addVertex(T.label, "C", "name", "c6", "order", 3);
Vertex c7 = this.sqlgGraph.addVertex(T.label, "C", "name", "c7", "order", 1);
Vertex c8 = this.sqlgGraph.addVertex(T.label, "C", "name", "c8", "order", 2);
Vertex c9 = this.sqlgGraph.addVertex(T.label, "C", "name", "c9", "order", 3);
b1.addEdge("bc", c1);
b1.addEdge("bc", c2);
b1.addEdge("bc", c3);
b2.addEdge("bc", c4);
b2.addEdge("bc", c5);
b2.addEdge("bc", c6);
b3.addEdge("bc", c7);
b3.addEdge("bc", c8);
b3.addEdge("bc", c9);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V().hasLabel("A").order().by("order").local(__.optional(__.outE("ab").order().by("order", Order.decr).inV().local(__.optional(__.out("bc").order().by("order", Order.decr))))).path();
List<Path> paths = traversal.toList();
for (Path path : paths) {
if (path.objects().size() > 3) {
System.out.println(path.toString() + " " + ((Vertex) path.objects().get(3)).<String>value("name"));
} else {
System.out.println(path.toString() + " " + ((Vertex) path.objects().get(2)).<String>value("name"));
}
}
Assert.assertEquals(19, paths.size());
Assert.assertEquals(a1, paths.get(0).objects().get(0));
Assert.assertEquals(c9, paths.get(0).objects().get(3));
Assert.assertEquals(a1, paths.get(1).objects().get(0));
Assert.assertEquals(c8, paths.get(1).objects().get(3));
Assert.assertEquals(a1, paths.get(2).objects().get(0));
Assert.assertEquals(c7, paths.get(2).objects().get(3));
Assert.assertEquals(a1, paths.get(3).objects().get(0));
Assert.assertEquals(c6, paths.get(3).objects().get(3));
Assert.assertEquals(a1, paths.get(4).objects().get(0));
Assert.assertEquals(c5, paths.get(4).objects().get(3));
Assert.assertEquals(a1, paths.get(5).objects().get(0));
Assert.assertEquals(c4, paths.get(5).objects().get(3));
Assert.assertEquals(a1, paths.get(6).objects().get(0));
Assert.assertEquals(c3, paths.get(6).objects().get(3));
Assert.assertEquals(a1, paths.get(7).objects().get(0));
Assert.assertEquals(c2, paths.get(7).objects().get(3));
Assert.assertEquals(a1, paths.get(8).objects().get(0));
Assert.assertEquals(c1, paths.get(8).objects().get(3));
Assert.assertEquals(a1, paths.get(9).objects().get(0));
Assert.assertEquals(b4, paths.get(9).objects().get(2));
Assert.assertEquals(a2, paths.get(10).objects().get(0));
Assert.assertEquals(c9, paths.get(10).objects().get(3));
Assert.assertEquals(a2, paths.get(11).objects().get(0));
Assert.assertEquals(c8, paths.get(11).objects().get(3));
Assert.assertEquals(a2, paths.get(12).objects().get(0));
Assert.assertEquals(c7, paths.get(12).objects().get(3));
Assert.assertEquals(a2, paths.get(13).objects().get(0));
Assert.assertEquals(c6, paths.get(13).objects().get(3));
Assert.assertEquals(a2, paths.get(14).objects().get(0));
Assert.assertEquals(c5, paths.get(14).objects().get(3));
Assert.assertEquals(a2, paths.get(15).objects().get(0));
Assert.assertEquals(c4, paths.get(15).objects().get(3));
Assert.assertEquals(a2, paths.get(16).objects().get(0));
Assert.assertEquals(c3, paths.get(16).objects().get(3));
Assert.assertEquals(a2, paths.get(17).objects().get(0));
Assert.assertEquals(c2, paths.get(17).objects().get(3));
Assert.assertEquals(a2, paths.get(18).objects().get(0));
Assert.assertEquals(c1, paths.get(18).objects().get(3));
}
Aggregations