use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal 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.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestUnoptimizedRepeatStep method testRepeatStepWithLimit.
@Test
public void testRepeatStepWithLimit() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B");
a1.addEdge("ab", b1);
a2.addEdge("ab", b2);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").until(__.has(T.label, "B")).repeat(__.out()).limit(1);
Assert.assertEquals(4, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(2) instanceof RepeatStep);
Assert.assertTrue(traversal.getSteps().get(3) instanceof RangeGlobalStep);
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(1) instanceof SqlgRepeatStepBarrier);
Assert.assertEquals(1, vertices.size());
Assert.assertTrue(vertices.contains(b1) || vertices.contains(b2));
vertices = this.sqlgGraph.traversal().V().hasLabel("A").repeat(__.out()).until(__.has(T.label, "B")).limit(1).toList();
Assert.assertEquals(1, vertices.size());
Assert.assertTrue(vertices.contains(b1) || vertices.contains(b2));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestUnoptimizedRepeatStep method testRepeatStepWithUntilLast.
// @Test
// public void testRepeatUtilFirstPerformance() {
// this.sqlgGraph.tx().normalBatchModeOn();
// for (int i = 0; i < 10_000; i++) {
// Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
// Vertex a2 = 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 c2 = this.sqlgGraph.addVertex(T.label, "C");
// Vertex x = this.sqlgGraph.addVertex(T.label, "X", "name", "hallo");
// a1.addEdge("ab", b1);
// a2.addEdge("ab", b2);
// b1.addEdge("bc", c1);
// b2.addEdge("bc", c2);
//
// b1.addEdge("bx", x);
// c2.addEdge("cx", x);
// }
// this.sqlgGraph.tx().commit();
//
// StopWatch stopWatch = new StopWatch();
// for (int i = 0; i < 1000; i++) {
// stopWatch.start();
// DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal()
// .V().hasLabel("A")
// .repeat(__.out())
// .until(__.out().has("name", "hallo"));
// List<Vertex> vertices = traversal.toList();
// Assert.assertEquals(20_000, vertices.size());
// stopWatch.stop();
// System.out.println(stopWatch.toString());
// stopWatch.reset();
// }
// }
@Test
public void testRepeatStepWithUntilLast() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a2 = 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 c2 = this.sqlgGraph.addVertex(T.label, "C");
Vertex x = this.sqlgGraph.addVertex(T.label, "X", "name", "hallo");
a1.addEdge("ab", b1);
a2.addEdge("ab", b2);
b1.addEdge("bc", c1);
b2.addEdge("bc", c2);
b1.addEdge("bx", x);
c2.addEdge("cx", x);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").repeat(__.out()).until(__.out().has("name", "hallo"));
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(2, vertices.size());
Assert.assertTrue(vertices.contains(b1) || vertices.contains(c1));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestUnoptimizedRepeatStep method testRepeatStepWithUntilFirst.
@Test
public void testRepeatStepWithUntilFirst() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a2 = 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 c2 = this.sqlgGraph.addVertex(T.label, "C");
Vertex x = this.sqlgGraph.addVertex(T.label, "X", "name", "hallo");
a1.addEdge("ab", b1);
a2.addEdge("ab", b2);
b1.addEdge("bc", c1);
b2.addEdge("bc", c2);
b1.addEdge("bx", x);
c2.addEdge("cx", x);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").until(__.out().has("name", "hallo")).repeat(__.out());
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(2, vertices.size());
Assert.assertTrue(vertices.contains(b1) && vertices.contains(c2));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestUnoptimizedRepeatStep method testRepeatStepWithUntilFirstEmitFirst.
@Test
public void testRepeatStepWithUntilFirstEmitFirst() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A");
Vertex a2 = 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 c2 = this.sqlgGraph.addVertex(T.label, "C");
Vertex x = this.sqlgGraph.addVertex(T.label, "X", "name", "hallo");
a1.addEdge("ab", b1);
a2.addEdge("ab", b2);
b1.addEdge("bc", c1);
b2.addEdge("bc", c2);
b1.addEdge("bx", x);
c2.addEdge("cx", x);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").until(__.out().has("name", "hallo")).emit().repeat(__.out());
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(5, vertices.size());
Assert.assertTrue(vertices.contains(a1) && vertices.contains(a2) && vertices.contains(b1) && vertices.contains(b2) && vertices.contains(c2));
}
Aggregations