use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestLocalVertexStepOptional method g_VX2X_optionalXoutXknowsXX.
@Test
public void g_VX2X_optionalXoutXknowsXX() throws IOException {
loadModern(this.sqlgGraph);
this.sqlgGraph.tx().commit();
Graph g = this.sqlgGraph;
assertModernGraph(g, true, false);
Object vadas = convertToVertexId(g, "vadas");
Vertex vadasVertex = g.traversal().V(vadas).next();
List<Path> paths = g.traversal().V(vadasVertex).local(__.optional(__.out("knows")).path()).toList();
Assert.assertEquals(1, paths.size());
List<Predicate<Path>> pathsToAssert = Arrays.asList(p -> p.size() == 1 && p.get(0).equals(vadasVertex));
for (Predicate<Path> pathPredicate : pathsToAssert) {
Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
Assert.assertTrue(path.isPresent());
Assert.assertTrue(paths.remove(path.get()));
}
Assert.assertTrue(paths.isEmpty());
List<Vertex> vertices = g.traversal().V(vadasVertex).local(__.optional(__.out("knows"))).toList();
Assert.assertEquals(1, vertices.size());
Assert.assertEquals(vadasVertex, vertices.get(0));
paths = g.traversal().V().local(__.optional(__.out().optional(__.out())).path()).toList();
for (Path path : paths) {
System.out.println(path.toString());
}
Assert.assertEquals(10, paths.size());
pathsToAssert = Arrays.asList(p -> p.size() == 2 && p.get(0).equals(convertToVertex(g, "marko")) && p.get(1).equals(convertToVertex(g, "lop")), p -> p.size() == 2 && p.get(0).equals(convertToVertex(g, "marko")) && p.get(1).equals(convertToVertex(g, "vadas")), p -> p.size() == 3 && p.get(0).equals(convertToVertex(g, "marko")) && p.get(1).equals(convertToVertex(g, "josh")) && p.get(2).equals(convertToVertex(g, "lop")), p -> p.size() == 3 && p.get(0).equals(convertToVertex(g, "marko")) && p.get(1).equals(convertToVertex(g, "josh")) && p.get(2).equals(convertToVertex(g, "ripple")), p -> p.size() == 1 && p.get(0).equals(convertToVertex(g, "vadas")), p -> p.size() == 1 && p.get(0).equals(convertToVertex(g, "lop")), p -> p.size() == 2 && p.get(0).equals(convertToVertex(g, "josh")) && p.get(1).equals(convertToVertex(g, "lop")), p -> p.size() == 2 && p.get(0).equals(convertToVertex(g, "josh")) && p.get(1).equals(convertToVertex(g, "ripple")), p -> p.size() == 1 && p.get(0).equals(convertToVertex(g, "ripple")), p -> p.size() == 2 && p.get(0).equals(convertToVertex(g, "peter")) && p.get(1).equals(convertToVertex(g, "lop")));
for (Predicate<Path> pathPredicate : pathsToAssert) {
Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
Assert.assertTrue(path.isPresent());
Assert.assertTrue(paths.remove(path.get()));
}
Assert.assertTrue(paths.isEmpty());
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestLocalVertexStepOptional method testLocalVertexStepNotOptimized.
@Test
public void testLocalVertexStepNotOptimized() {
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();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.gt.V().local(__.optional(__.where(__.has(T.label, "A")).out())).path();
Assert.assertEquals(3, traversal.getSteps().size());
List<Path> paths = traversal.toList();
Assert.assertEquals(3, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(1) instanceof SqlgLocalStepBarrier);
SqlgLocalStepBarrier<?, ?> localStep = (SqlgLocalStepBarrier) traversal.getSteps().get(1);
List<SqlgVertexStep> sqlgVertexStepCompileds = TraversalHelper.getStepsOfAssignableClassRecursively(SqlgVertexStep.class, localStep.getLocalChildren().get(0));
Assert.assertEquals(1, sqlgVertexStepCompileds.size());
SqlgVertexStep sqlgVertexStepCompiled = sqlgVertexStepCompileds.get(0);
assertStep(sqlgVertexStepCompiled, false, false, false, true);
Assert.assertEquals(3, paths.size());
List<Predicate<Path>> pathsToAssert = Arrays.asList(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1), p -> p.size() == 1 && p.get(0).equals(a2), p -> p.size() == 1 && p.get(0).equals(b1));
for (Predicate<Path> pathPredicate : pathsToAssert) {
Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
Assert.assertTrue(path.isPresent());
Assert.assertTrue(paths.remove(path.get()));
}
Assert.assertTrue(paths.isEmpty());
// while (traversal.hasNext()) {
// System.out.println(traversal.next());
// }
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestLocalVertexStepOptional method testOptionalOnNonExistingEdgeLabel.
@Test
public void testOptionalOnNonExistingEdgeLabel() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1");
a1.addEdge("ab", b1);
this.sqlgGraph.tx().commit();
List<Path> paths = this.sqlgGraph.traversal().V(a1).local(__.optional(__.out("ab", "bb")).path()).toList();
Assert.assertEquals(1, paths.size());
List<Predicate<Path>> pathsToAssert = Arrays.asList(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1));
for (Predicate<Path> pathPredicate : pathsToAssert) {
Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
Assert.assertTrue(path.isPresent());
Assert.assertTrue(paths.remove(path.get()));
}
Assert.assertTrue(paths.isEmpty());
paths = this.sqlgGraph.traversal().V(a1).local(__.optional(__.out("bb")).path()).toList();
Assert.assertEquals(1, paths.size());
pathsToAssert = Arrays.asList(p -> p.size() == 1 && p.get(0).equals(a1));
for (Predicate<Path> pathPredicate : pathsToAssert) {
Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
Assert.assertTrue(path.isPresent());
Assert.assertTrue(paths.remove(path.get()));
}
Assert.assertTrue(paths.isEmpty());
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestLocalVertexStepOptional method testOptionalNestedMultipleEdgeLabels.
@Test
public void testOptionalNestedMultipleEdgeLabels() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
b1.addEdge("bc", c1);
Vertex bb1 = this.sqlgGraph.addVertex(T.label, "BB");
Vertex bb2 = this.sqlgGraph.addVertex(T.label, "BB");
Vertex cc1 = this.sqlgGraph.addVertex(T.label, "CC");
a1.addEdge("abb", bb1);
a1.addEdge("abb", bb2);
bb1.addEdge("bbcc", cc1);
this.sqlgGraph.tx().commit();
List<Path> paths = this.sqlgGraph.traversal().V(a1).local(__.optional(__.out("ab", "abb").optional(__.out("bc", "bbcc"))).path()).toList();
Assert.assertEquals(4, paths.size());
List<Predicate<Path>> pathsToAssert = Arrays.asList(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1), p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b2), p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(bb1) && p.get(2).equals(cc1), p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(bb2));
for (Predicate<Path> pathPredicate : pathsToAssert) {
Optional<Path> path = paths.stream().filter(pathPredicate).findAny();
Assert.assertTrue(path.isPresent());
Assert.assertTrue(paths.remove(path.get()));
}
Assert.assertTrue(paths.isEmpty());
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class NetAggregateTest method test2.
@Test
public void test2() {
StopWatch stopWatch = new StopWatch();
stopWatch.start();
// List<Vertex> vertices = this.sqlgGraph.traversal().V().hasLabel("Transmission").toList();
List<Path> vertices = this.sqlgGraph.traversal().V().hasLabel("Transmission").repeat(__.both("link").simplePath()).until(__.or(__.has("type", P.within("HubSite", "ASwitch", "BSwitch")), __.has("excluded", true), __.loops().is(12))).path().toList();
System.out.println(vertices.size());
stopWatch.stop();
System.out.println(stopWatch.toString());
}
Aggregations