use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestLocalVertexStepRepeatStep method testLocalRepeatStepEmitTimesBefore.
@Test
public void testLocalRepeatStepEmitTimesBefore() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
a1.addEdge("ab", b1);
b1.addEdge("bc", c1);
this.sqlgGraph.tx().commit();
List<Path> paths = this.gt.V(a1).local(__.<Vertex>emit().times(2).repeat(__.out())).path().toList();
for (Path path : paths) {
System.out.println(path);
}
assertEquals(3, paths.size());
List<Predicate<Path>> pathsToAssert = Arrays.asList(p -> p.size() == 1 && p.get(0).equals(a1), p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1), p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1));
for (Predicate<Path> pathPredicate : pathsToAssert) {
Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
assertTrue(path.isPresent());
assertTrue(paths.remove(path.get()));
}
assertTrue(paths.isEmpty());
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestLocalVertexStepRepeatStep method testEmitTimes2MultiplePaths.
@Test
public void testEmitTimes2MultiplePaths() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
a1.addEdge("aa", a2);
a2.addEdge("ab", b1);
this.sqlgGraph.tx().commit();
List<Path> paths = this.sqlgGraph.traversal().V().local(__.<Vertex>emit().times(2).repeat(__.out()).path()).toList();
assertEquals(6, paths.size());
assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a1)));
assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a2)));
assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(b1)));
assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(a2)));
assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(a2) && p.get(1).equals(b1)));
assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(a2) && p.get(2).equals(b1)));
paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(a1)).findAny().get());
paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(a2)).findAny().get());
paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(b1)).findAny().get());
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(a2)).findAny().get());
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(a2) && p.get(1).equals(b1)).findAny().get());
paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(a2) && p.get(2).equals(b1)).findAny().get());
assertTrue(paths.isEmpty());
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestLocalVertexStepWithOrder method testSqlgVertexStepOrderStartsProperly.
@Test
public void testSqlgVertexStepOrderStartsProperly() {
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");
a1.addEdge("ab", b1, "order", 1);
a1.addEdge("ab", b2, "order", 2);
a1.addEdge("ab", b3, "order", 3);
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(__.outE("ab").order().by("order", Order.decr).inV().local(__.out("bc").order().by("order", Order.decr))).path();
List<Path> paths = traversal.toList();
for (Path path : paths) {
System.out.println(path.toString() + " " + ((Vertex) path.objects().get(3)).<String>value("name"));
}
Assert.assertEquals(18, 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(a2, paths.get(9).objects().get(0));
Assert.assertEquals(c9, paths.get(9).objects().get(3));
Assert.assertEquals(a2, paths.get(10).objects().get(0));
Assert.assertEquals(c8, paths.get(10).objects().get(3));
Assert.assertEquals(a2, paths.get(11).objects().get(0));
Assert.assertEquals(c7, paths.get(11).objects().get(3));
Assert.assertEquals(a2, paths.get(12).objects().get(0));
Assert.assertEquals(c6, paths.get(12).objects().get(3));
Assert.assertEquals(a2, paths.get(13).objects().get(0));
Assert.assertEquals(c5, paths.get(13).objects().get(3));
Assert.assertEquals(a2, paths.get(14).objects().get(0));
Assert.assertEquals(c4, paths.get(14).objects().get(3));
Assert.assertEquals(a2, paths.get(15).objects().get(0));
Assert.assertEquals(c3, paths.get(15).objects().get(3));
Assert.assertEquals(a2, paths.get(16).objects().get(0));
Assert.assertEquals(c2, paths.get(16).objects().get(3));
Assert.assertEquals(a2, paths.get(17).objects().get(0));
Assert.assertEquals(c1, paths.get(17).objects().get(3));
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestVertexStepPerformance method testLocalVertexStepNotOptimizedPerformance.
// @Test
public void testLocalVertexStepNotOptimizedPerformance() {
this.sqlgGraph.tx().normalBatchModeOn();
for (int i = 0; i < 10_000; i++) {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
a1.addEdge("ab", b1);
}
this.sqlgGraph.tx().commit();
StopWatch stopWatch = new StopWatch();
for (int i = 0; i < 1000; i++) {
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.gt.V().local(__.optional(__.where(__.has(T.label, "A")).out())).path();
stopWatch.start();
List<Path> paths = traversal.toList();
stopWatch.stop();
System.out.println(stopWatch.toString());
stopWatch.reset();
Assert.assertEquals(30_000, paths.size());
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestRepeatStepGraphOut method testOnDuplicatePathsFromVertexTimes1EmitAfter.
@Test
public void testOnDuplicatePathsFromVertexTimes1EmitAfter() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
a1.addEdge("ab", b1);
b1.addEdge("ba", a2);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V().repeat(__.out("ab", "ba")).emit().times(1).path();
Assert.assertEquals(3, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertEquals(2, paths.size());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1)).findAny().get());
Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(b1) && p.get(1).equals(a2)));
paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(b1) && p.get(1).equals(a2)).findAny().get());
Assert.assertTrue(paths.isEmpty());
}
Aggregations