use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestMultipleLabels method testSameElementHasMultipleLabels.
@Test
public void testSameElementHasMultipleLabels() {
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", "b2");
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
b1.addEdge("bc", c1);
b2.addEdge("bc", c1);
b3.addEdge("bc", c1);
this.sqlgGraph.tx().commit();
List<Path> paths = this.sqlgGraph.traversal().V(a1.id()).as("a", "b").out("ab").as("a", "b").out("bc").path().toList();
List<Vertex> vertices = this.sqlgGraph.traversal().V(a1.id()).out("ab").out("bc").toList();
for (Vertex v : vertices) {
System.out.println(v);
}
}
use of org.apache.tinkerpop.gremlin.process.traversal.Path in project sqlg by pietermartin.
the class TestLocalEdgeOtherVertexStep method testEdgeOtherVertexStepDeeper.
@Test
public void testEdgeOtherVertexStepDeeper() {
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");
Edge e1 = a1.addEdge("ab", b1);
b1.addEdge("bc", c1);
this.sqlgGraph.tx().commit();
List<Vertex> vertices = this.sqlgGraph.traversal().V(a1).local(__.outE().otherV().out()).toList();
assertEquals(1, vertices.size());
assertEquals(c1, vertices.get(0));
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V(a1).local(__.outE().otherV().out()).path();
List<Path> paths = traversal.toList();
for (Path path : paths) {
System.out.println(path.toString());
}
assertEquals(1, paths.size());
List<Predicate<Path>> pathsToAssert = Arrays.asList(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(e1) && p.get(2).equals(b1) && p.get(3).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 TestLocalRepeatStep method testLocalRepeatStep.
@Test
public void testLocalRepeatStep() {
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.sqlgGraph.traversal().V(a1).local(__.<Vertex>emit().times(2).repeat(__.out())).path().toList();
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 TestLocalVertexStepOptional method testLocalOptionalNested.
@Test
public void testLocalOptionalNested() {
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);
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2");
a2.addEdge("ab", b2);
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a3");
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V().local(__.optional(__.out().optional(__.out()))).path();
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, true);
Assert.assertEquals(6, 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(b1) && p.get(1).equals(c1), p -> p.size() == 2 && p.get(0).equals(a2) && p.get(1).equals(b2), p -> p.size() == 1 && p.get(0).equals(c1), p -> p.size() == 1 && p.get(0).equals(b2), p -> p.size() == 1 && p.get(0).equals(a3));
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 testMultipleNestedOptional.
@Test
public void testMultipleNestedOptional() {
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");
Vertex cc1 = this.sqlgGraph.addVertex(T.label, "CC");
Vertex cc2 = this.sqlgGraph.addVertex(T.label, "CC");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
b1.addEdge("bc", c1);
b2.addEdge("bcc", cc2);
c1.addEdge("ccc", cc1);
this.sqlgGraph.tx().commit();
List<Path> paths = this.sqlgGraph.traversal().V(a1).local(__.optional(__.out("ab").optional(__.out("bc"))).path()).toList();
Assert.assertEquals(2, 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));
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());
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V(a1).local(__.optional(__.out("ab").optional(__.out("bc"))).out().path());
paths = traversal.toList();
Assert.assertEquals(2, paths.size());
pathsToAssert = Arrays.asList(p -> p.size() == 4 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1) && p.get(3).equals(cc1), p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b2) && p.get(2).equals(cc2));
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());
}
Aggregations