use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestLocalStepCompile method testOrderByToSelf.
@Test
public void testOrderByToSelf() {
Vertex root = this.sqlgGraph.addVertex(T.label, "Root");
Vertex folder1 = this.sqlgGraph.addVertex(T.label, "Folder");
Vertex folder2 = this.sqlgGraph.addVertex(T.label, "Folder");
Edge e1 = root.addEdge("rootFolder", folder1);
Edge e2 = folder1.addEdge("subFolder", folder2, "sequence", 1);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal) this.sqlgGraph.traversal().V(folder1).outE("subFolder").as("e").inV().as("v").select("e", "v").order().by(__.select("e").by("sequence"), Order.incr).map(m -> (Vertex) m.get().get("v"));
Assert.assertEquals(6, traversal.getSteps().size());
List<Vertex> result = traversal.toList();
Assert.assertEquals(3, traversal.getSteps().size());
Assert.assertEquals(1, result.size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestLocalStepCompile method testSelectVertexAndEdgeOrderByEdge.
@Test
public void testSelectVertexAndEdgeOrderByEdge() {
Vertex god = this.sqlgGraph.addVertex(T.label, "God");
Vertex fantasy1 = this.sqlgGraph.addVertex(T.label, "Fantasy", "name", "fan1");
Vertex fantasy2 = this.sqlgGraph.addVertex(T.label, "Fantasy", "name", "fan2");
Vertex fantasy3 = this.sqlgGraph.addVertex(T.label, "Fantasy", "name", "fan3");
Vertex fantasy4 = this.sqlgGraph.addVertex(T.label, "Fantasy", "name", "fan4");
Edge e1 = god.addEdge("godDream", fantasy1, "sequence", 1);
Edge e2 = god.addEdge("godDream", fantasy2, "sequence", 2);
Edge e3 = god.addEdge("godDream", fantasy3, "sequence", 3);
Edge e4 = god.addEdge("godDream", fantasy4, "sequence", 4);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Map<String, Object>> traversal = (DefaultGraphTraversal<Vertex, Map<String, Object>>) this.sqlgGraph.traversal().V(god).outE("godDream").as("e").inV().as("v").select("e", "v").order().by(__.select("e").by("sequence"), Order.decr);
Assert.assertEquals(5, traversal.getSteps().size());
List<Map<String, Object>> result = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertEquals(4, result.size());
Assert.assertEquals(fantasy4, result.get(0).get("v"));
Assert.assertEquals(fantasy3, result.get(1).get("v"));
Assert.assertEquals(fantasy2, result.get(2).get("v"));
Assert.assertEquals(fantasy1, result.get(3).get("v"));
Assert.assertEquals(e4, result.get(0).get("e"));
Assert.assertEquals(e3, result.get(1).get("e"));
Assert.assertEquals(e2, result.get(2).get("e"));
Assert.assertEquals(e1, result.get(3).get("e"));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestLocalStepCompile method testOrderbyDuplicatePath.
@Test
public void testOrderbyDuplicatePath() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "aa");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "a");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "c");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "ab");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "ac");
a1.addEdge("ab", b1);
a1.addEdge("ab", b2);
a1.addEdge("ab", b3);
b1.addEdge("ba", a2);
b1.addEdge("ba", a3);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V(a1).out().out().order().by("name", Order.decr);
Assert.assertEquals(4, traversal.getSteps().size());
List<Vertex> result = traversal.toList();
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertEquals(2, result.size());
Assert.assertEquals(a3, result.get(0));
Assert.assertEquals(a2, result.get(1));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal 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.dsl.graph.DefaultGraphTraversal 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