Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal#toList()
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal#toList() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: TestRepeatStepVertexOut.java From sqlg with MIT License | 6 votes |
@Test public void testOnDuplicatePathsFromVertexTimesAfter() { 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(a1, a2).emit().repeat(__.out("ab", "ba")).times(3).path(); Assert.assertEquals(3, traversal.getSteps().size()); List<Path> paths = traversal.toList(); Assert.assertEquals(2, traversal.getSteps().size()); Assert.assertEquals(4, paths.size()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a1))); paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(a1)).findAny().get()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a2))); paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(a2)).findAny().get()); 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() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(a2))); paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(a2)).findAny().get()); Assert.assertTrue(paths.isEmpty()); }
Example 2
Source File: TestHasLabelAndId.java From sqlg with MIT License | 6 votes |
@Test public void testInWithHasLabel() { Vertex a = this.sqlgGraph.addVertex(T.label, "A"); Vertex b = this.sqlgGraph.addVertex(T.label, "B"); Vertex c = this.sqlgGraph.addVertex(T.label, "C"); Vertex d = this.sqlgGraph.addVertex(T.label, "D"); b.addEdge("ab", a); c.addEdge("ac", a); d.addEdge("ad", a); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V().hasLabel("A").in().hasLabel("B"); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(1, vertices.size()); Assert.assertEquals(1, traversal.getSteps().size()); Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0); Assert.assertEquals(2, sqlgGraphStep.getReplacedSteps().size()); ReplacedStep replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(0); Assert.assertEquals(1, replacedStep.getLabelHasContainers().size()); replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(1); Assert.assertEquals(1, replacedStep.getLabelHasContainers().size()); }
Example 3
Source File: TestRepeatStepVertexOut.java From sqlg with MIT License | 6 votes |
@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(a1, a2, b1).repeat(__.out("ab", "ba")).emit().times(2).path(); Assert.assertEquals(3, traversal.getSteps().size()); List<Path> paths = traversal.toList(); Assert.assertEquals(2, traversal.getSteps().size()); Assert.assertEquals(3, 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.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(a2))); paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(a2)).findAny().get()); Assert.assertTrue(paths.isEmpty()); }
Example 4
Source File: TestLocalStepCompile.java From sqlg with MIT License | 6 votes |
@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"); root.addEdge("rootFolder", folder1); folder1.addEdge("subFolder", folder2, "sequence", 1); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V(folder1) .outE("subFolder").as("e") .inV().as("v") .select("e", "v") .order().by(__.select("e").by("sequence"), Order.asc) .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()); }
Example 5
Source File: TestGremlinOptional.java From sqlg with MIT License | 6 votes |
@Test public void testOptionalOutNotThere() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A"); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B"); b1.addEdge("knows", a1); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal() .V(a1) .optional( __.out("knows") ) .path(); Assert.assertEquals(3, traversal.getSteps().size()); List<Path> paths = traversal.toList(); Assert.assertEquals(2, traversal.getSteps().size()); Assert.assertEquals(1, paths.size()); }
Example 6
Source File: TestGraphStepOrderBy.java From sqlg with MIT License | 6 votes |
@Test public void testSimple() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "order", 1); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "order", 1); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "order", 2); Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "order", 3); a1.addEdge("ab", b1); a1.addEdge("ab", b2); a1.addEdge("ab", b3); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V().hasLabel("A") .out() .order().by("order", Order.decr); Assert.assertEquals(4, traversal.getSteps().size()); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(1, traversal.getSteps().size()); assertStep(traversal.getSteps().get(0), true, false, false, false); Assert.assertEquals(3, vertices.size()); Assert.assertEquals(b3, vertices.get(0)); Assert.assertEquals(b2, vertices.get(1)); Assert.assertEquals(b1, vertices.get(2)); }
Example 7
Source File: TestRepeatStepVertexOut.java From sqlg with MIT License | 6 votes |
@Test public void testSmallerRepeatWithEmitFirst() { 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 c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1"); a1.addEdge("ab", b1); a1.addEdge("ab", b2); b1.addEdge("bc", c1); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal() .V(a1.id()).emit().repeat(__.out("ab", "bc")).times(2).path(); Assert.assertEquals(3, traversal.getSteps().size()); List<Path> paths = traversal.toList(); Assert.assertEquals(2, traversal.getSteps().size()); Assert.assertEquals(4, paths.size()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a1))); paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(a1)).findAny().get()); 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(a1) && p.get(1).equals(b2))); paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b2)).findAny().get()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1))); paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(c1)).findAny().get()); Assert.assertTrue(paths.isEmpty()); }
Example 8
Source File: TestGraphStepOrderBy.java From sqlg with MIT License | 6 votes |
private void testOrderBy_assert(SqlgGraph sqlgGraph, Vertex a1, Vertex a2, Vertex a3, Vertex b1, Vertex b2, Vertex b3) { DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) sqlgGraph.traversal() .V().hasLabel("A") .order() .by("name", Order.incr).by("surname", Order.decr); Assert.assertEquals(3, traversal.getSteps().size()); List<Vertex> result = traversal.toList(); Assert.assertEquals(1, traversal.getSteps().size()); Assert.assertEquals(6, result.size()); Assert.assertEquals(a3, result.get(0)); Assert.assertEquals(a2, result.get(1)); Assert.assertEquals(a1, result.get(2)); Assert.assertEquals(b3, result.get(3)); Assert.assertEquals(b2, result.get(4)); Assert.assertEquals(b1, result.get(5)); }
Example 9
Source File: TestHasLabelAndId.java From sqlg with MIT License | 6 votes |
@Test public void testConsecutiveEqHasIdAndLabels4() { Vertex a = this.sqlgGraph.addVertex(T.label, "A"); Vertex b = this.sqlgGraph.addVertex(T.label, "B"); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B"); Vertex c = this.sqlgGraph.addVertex(T.label, "C"); Vertex d = this.sqlgGraph.addVertex(T.label, "D"); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V().hasLabel("A", "B", "C").hasId(b.id()); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(1, vertices.size()); Assert.assertEquals(b, vertices.get(0)); Assert.assertEquals(1, traversal.getSteps().size()); Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0); Assert.assertEquals(1, sqlgGraphStep.getReplacedSteps().size()); ReplacedStep replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(0); Assert.assertEquals(2, replacedStep.getLabelHasContainers().size()); }
Example 10
Source File: TestRepeatWithOrderAndRange.java From sqlg with MIT License | 5 votes |
@Test public void testRepeatWithOrder() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a"); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1", "order", 1); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2", "order", 2); Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name", "b3", "order", 3); a1.addEdge("ab", b1); a1.addEdge("ab", b2); a1.addEdge("ab", b3); Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1", "order", 4); Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "c2", "order", 5); Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "c3", "order", 6); b1.addEdge("bc", c1); b1.addEdge("bc", c2); b1.addEdge("bc", c3); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V().hasLabel("A") .repeat( __.out().order().by("order", Order.decr) ).times(2); Assert.assertEquals(3, traversal.getSteps().size()); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(1, traversal.getSteps().size()); Assert.assertEquals(3, vertices.size()); Assert.assertEquals(c3, vertices.get(0)); Assert.assertEquals(c2, vertices.get(1)); Assert.assertEquals(c1, vertices.get(2)); }
Example 11
Source File: TestHasLabelAndId.java From sqlg with MIT License | 5 votes |
@Test public void testInWithHasLabelAndHasWithoutId2() { Vertex a = this.sqlgGraph.addVertex(T.label, "A"); Vertex b = this.sqlgGraph.addVertex(T.label, "B"); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B"); Vertex c = this.sqlgGraph.addVertex(T.label, "C"); Vertex d = this.sqlgGraph.addVertex(T.label, "D"); b.addEdge("ab", a); b2.addEdge("ab", a); c.addEdge("ac", a); d.addEdge("ad", a); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V().hasLabel("A").in().hasLabel("B", "C", "D").has(T.id, P.without(b.id(), c.id())); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(2, vertices.size()); Assert.assertTrue(vertices.contains(b2) && vertices.contains(d)); Assert.assertEquals(1, traversal.getSteps().size()); Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0); Assert.assertEquals(2, sqlgGraphStep.getReplacedSteps().size()); ReplacedStep replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(0); Assert.assertEquals(1, replacedStep.getLabelHasContainers().size()); replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(1); Assert.assertEquals(1, replacedStep.getLabelHasContainers().size()); }
Example 12
Source File: TestHasLabelAndId.java From sqlg with MIT License | 5 votes |
@Test public void testInWithHasLabelAndHasId() { Vertex a = this.sqlgGraph.addVertex(T.label, "A"); Vertex b = this.sqlgGraph.addVertex(T.label, "B"); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B"); Vertex c = this.sqlgGraph.addVertex(T.label, "C"); Vertex d = this.sqlgGraph.addVertex(T.label, "D"); b.addEdge("ab", a); b2.addEdge("ab", a); c.addEdge("ac", a); d.addEdge("ad", a); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V().hasLabel("A").in().hasLabel("B").hasId(b.id()); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(1, vertices.size()); Assert.assertEquals(b, vertices.get(0)); Assert.assertEquals(1, traversal.getSteps().size()); Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0); Assert.assertEquals(2, sqlgGraphStep.getReplacedSteps().size()); ReplacedStep replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(0); Assert.assertEquals(1, replacedStep.getLabelHasContainers().size()); replacedStep = (ReplacedStep) sqlgGraphStep.getReplacedSteps().get(1); Assert.assertEquals(2, replacedStep.getLabelHasContainers().size()); }
Example 13
Source File: TestRepeatStepGraphOut.java From sqlg with MIT License | 5 votes |
@Test public void testOnDuplicatePathsFromVertexTimesAfter() { 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().emit().repeat(__.out("ab", "ba")).times(2).path(); Assert.assertEquals(3, traversal.getSteps().size()); List<Path> paths = traversal.toList(); Assert.assertEquals(2, traversal.getSteps().size()); Assert.assertEquals(6, paths.size()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a1))); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1))); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(a2))); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a2))); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(b1))); 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() == 1 && p.get(0).equals(a1)).findAny().orElseThrow(IllegalStateException::new)); paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(b1)).findAny().orElseThrow(IllegalStateException::new)); paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(b1) && p.get(2).equals(a2)).findAny().orElseThrow(IllegalStateException::new)); paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(a2)).findAny().orElseThrow(IllegalStateException::new)); paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(b1)).findAny().orElseThrow(IllegalStateException::new)); paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(b1) && p.get(1).equals(a2)).findAny().orElseThrow(IllegalStateException::new)); Assert.assertTrue(paths.isEmpty()); }
Example 14
Source File: TestPathStep.java From sqlg with MIT License | 5 votes |
@Test public void testNameWithMultipleSameLabel() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1"); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2"); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a3"); 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); a2.addEdge("ab", b2); a3.addEdge("ab", b3); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Map<String, Object>> traversal = (DefaultGraphTraversal<Vertex, Map<String, Object>>)this.sqlgGraph.traversal() .V().as("a") .out().as("a") .in().as("a") .select(Pop.all,"a", "a", "a"); Assert.assertEquals(4, traversal.getSteps().size()); List<Map<String, Object>> result = traversal.toList(); Assert.assertEquals(2, traversal.getSteps().size()); Assert.assertEquals(3, result.size()); Object o1 = result.get(0).get("a"); Assert.assertTrue(o1 instanceof List); @SuppressWarnings("unchecked") List<Vertex> ass = (List<Vertex>) o1; Assert.assertEquals(a1, ass.get(0)); Assert.assertEquals("a1", ass.get(0).value("name")); Assert.assertEquals(b1, ass.get(1)); Assert.assertEquals("b1", ass.get(1).value("name")); Assert.assertEquals(a1, ass.get(2)); Assert.assertEquals("a1", ass.get(2).value("name")); }
Example 15
Source File: TestGremlinCompileWithAs.java From sqlg with MIT License | 5 votes |
@SuppressWarnings("unchecked") private void testSchemaTableTreeNextSchemaTableTreeIsEdgeVertex_assert(SqlgGraph sqlgGraph, Vertex a1, Vertex b1, Vertex c1) { DefaultGraphTraversal<Vertex, Map<String, Vertex>> gt = (DefaultGraphTraversal)sqlgGraph.traversal().V(a1).out().as("b").out().as("c").select("b", "c"); Assert.assertEquals(4, gt.getSteps().size()); List<Map<String, Vertex>> list = gt.toList(); Assert.assertEquals(2, gt.getSteps().size()); Assert.assertEquals(1, list.size()); Assert.assertEquals(b1, list.get(0).get("b")); Assert.assertEquals(c1, list.get(0).get("c")); }
Example 16
Source File: TestUnoptimizedRepeatStep.java From sqlg with MIT License | 5 votes |
@Test public void testRepeatStepWithUntilLastEmitLast() { 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()) .emit() .until(__.out().has("name", "hallo")); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(3, vertices.size()); Assert.assertTrue(vertices.contains(b1) || vertices.contains(b2) || vertices.contains(c2)); }
Example 17
Source File: TestRepeatStepGraphIn.java From sqlg with MIT License | 4 votes |
@Test public void testEmitAfterTimesAfterAndBeforeIn() { 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"); Vertex d1 = this.sqlgGraph.addVertex(T.label, "D", "name", "d1"); a1.addEdge("ab", b1); b1.addEdge("bc", c1); c1.addEdge("cd", d1); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal() .V().hasLabel("D").repeat(__.in()).emit().times(3).path(); Assert.assertEquals(4, traversal.getSteps().size()); List<Path> paths = traversal.toList(); Assert.assertEquals(2, traversal.getSteps().size()); Assert.assertEquals(3, paths.size()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(d1) && p.get(1).equals(c1))); paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(d1) && p.get(1).equals(c1)).findAny().get()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(d1) && p.get(1).equals(c1) && p.get(2).equals(b1))); paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(d1) && p.get(1).equals(c1) && p.get(2).equals(b1)).findAny().get()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 4 && p.get(0).equals(d1) && p.get(1).equals(c1) && p.get(2).equals(b1) && p.get(3).equals(a1))); paths.remove(paths.stream().filter(p -> p.size() == 4 && p.get(0).equals(d1) && p.get(1).equals(c1) && p.get(2).equals(b1) && p.get(3).equals(a1)).findAny().get()); Assert.assertTrue(paths.isEmpty()); DefaultGraphTraversal<Vertex, Path> traversal1 = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal() .V().hasLabel("D").repeat(__.in()).emit().times(2).path(); Assert.assertEquals(4, traversal1.getSteps().size()); paths = traversal1.toList(); Assert.assertEquals(2, traversal1.getSteps().size()); Assert.assertEquals(2, paths.size()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(d1) && p.get(1).equals(c1))); paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(d1) && p.get(1).equals(c1)).findAny().get()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(d1) && p.get(1).equals(c1) && p.get(2).equals(b1))); paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(d1) && p.get(1).equals(c1) && p.get(2).equals(b1)).findAny().get()); Assert.assertTrue(paths.isEmpty()); DefaultGraphTraversal<Vertex, Path> traversal2 = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal() .V().hasLabel("D").times(1).repeat(__.in()).emit().path(); Assert.assertEquals(4, traversal2.getSteps().size()); paths = traversal2.toList(); Assert.assertEquals(2, traversal2.getSteps().size()); Assert.assertEquals(2, paths.size()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(d1) && p.get(1).equals(c1))); paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(d1) && p.get(1).equals(c1)).findAny().get()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(d1) && p.get(1).equals(c1))); paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(d1) && p.get(1).equals(c1)).findAny().get()); Assert.assertTrue(paths.isEmpty()); }
Example 18
Source File: TestRepeatStepGraphOut.java From sqlg with MIT License | 4 votes |
@Test public void testDuplicatePathToSelfEmitFirst() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1"); Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "a2"); Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "a3"); a1.addEdge("knows", a2); a2.addEdge("knows", a3); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V().emit().repeat(__.out("knows")).times(2); Assert.assertEquals(2, traversal.getSteps().size()); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(1, traversal.getSteps().size()); Assert.assertEquals(6, vertices.size()); Assert.assertTrue(vertices.remove(a1)); Assert.assertTrue(vertices.remove(a2)); Assert.assertTrue(vertices.remove(a3)); Assert.assertTrue(vertices.remove(a2)); Assert.assertTrue(vertices.remove(a3)); Assert.assertTrue(vertices.remove(a3)); Assert.assertEquals(0, vertices.size()); DefaultGraphTraversal<Vertex, Path> traversal1 = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal() .V().emit().repeat(__.out("knows")).times(2).path(); Assert.assertEquals(3, traversal1.getSteps().size()); List<Path> paths = traversal1.toList(); Assert.assertEquals(2, traversal1.getSteps().size()); Assert.assertEquals(6, paths.size()); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a1))); paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(a1)).findAny().orElseThrow(IllegalStateException::new)); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(a2))); paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(a1) && p.get(1).equals(a2)).findAny().orElseThrow(IllegalStateException::new)); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(a2) && p.get(2).equals(a3))); paths.remove(paths.stream().filter(p -> p.size() == 3 && p.get(0).equals(a1) && p.get(1).equals(a2) && p.get(2).equals(a3)).findAny().orElseThrow(IllegalStateException::new)); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a2))); paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(a2)).findAny().orElseThrow(IllegalStateException::new)); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 2 && p.get(0).equals(a2) && p.get(1).equals(a3))); paths.remove(paths.stream().filter(p -> p.size() == 2 && p.get(0).equals(a2) && p.get(1).equals(a3)).findAny().orElseThrow(IllegalStateException::new)); Assert.assertTrue(paths.stream().anyMatch(p -> p.size() == 1 && p.get(0).equals(a3))); paths.remove(paths.stream().filter(p -> p.size() == 1 && p.get(0).equals(a3)).findAny().orElseThrow(IllegalStateException::new)); Assert.assertTrue(paths.isEmpty()); }
Example 19
Source File: TestRepeatStepGraphOut.java From sqlg with MIT License | 4 votes |
@Test public void testRepeatWithEmitFirstWithPeriod() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name.AA", "a1"); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name.AA", "b1"); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name.AA", "b2"); Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "name.AA", "b3"); a1.addEdge("ab", b1); a1.addEdge("ab", b2); a1.addEdge("ab", b3); Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name.AA", "c1"); Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name.AA", "c2"); Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name.AA", "c3"); b1.addEdge("bc", c1); b1.addEdge("bc", c1); b1.addEdge("bc", c2); b1.addEdge("bc", c3); Vertex d1 = this.sqlgGraph.addVertex(T.label, "D", "name.AA", "d1"); Vertex d2 = this.sqlgGraph.addVertex(T.label, "D", "name.AA", "d2"); Vertex d3 = this.sqlgGraph.addVertex(T.label, "D", "name.AA", "d3"); c1.addEdge("cd", d1); c1.addEdge("cd", d2); c1.addEdge("cd", d3); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V().hasLabel("A").emit().repeat(__.out("ab", "bc", "cd")).times(3); Assert.assertEquals(3, traversal.getSteps().size()); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(1, traversal.getSteps().size()); Assert.assertEquals(14, vertices.size()); Assert.assertTrue(vertices.remove(a1)); Assert.assertTrue(vertices.remove(b1)); Assert.assertTrue(vertices.remove(b2)); Assert.assertTrue(vertices.remove(b3)); Assert.assertTrue(vertices.remove(c1)); Assert.assertTrue(vertices.remove(c1)); Assert.assertTrue(vertices.remove(c2)); Assert.assertTrue(vertices.remove(c3)); Assert.assertTrue(vertices.remove(d1)); Assert.assertTrue(vertices.remove(d2)); Assert.assertTrue(vertices.remove(d3)); Assert.assertTrue(vertices.remove(d1)); Assert.assertTrue(vertices.remove(d2)); Assert.assertTrue(vertices.remove(d3)); Assert.assertTrue(vertices.isEmpty()); }
Example 20
Source File: TestRepeatStepVertexOut.java From sqlg with MIT License | 4 votes |
@Test //This is not optimized public void testUntilRepeat() { 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", "b3"); a1.addEdge("ab", b1); a1.addEdge("ab", b2); a1.addEdge("ab", b3); Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1"); Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "c2"); Vertex c3 = this.sqlgGraph.addVertex(T.label, "C", "name", "c3"); b1.addEdge("bc", c1); b1.addEdge("bc", c2); b1.addEdge("bc", c3); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V(a1.id()) .repeat( __.out() ).until(__.hasLabel("C")); Assert.assertEquals(2, traversal.getSteps().size()); List<Vertex> t = traversal.toList(); Assert.assertEquals(2, traversal.getSteps().size()); Assert.assertEquals(3, t.size()); Assert.assertTrue(t.remove(c1)); Assert.assertTrue(t.remove(c2)); Assert.assertTrue(t.remove(c3)); Assert.assertTrue(t.isEmpty()); DefaultGraphTraversal<Vertex, Vertex> traversal1 = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V(a1.id()) .until(__.hasLabel("C")).repeat(__.out()); Assert.assertEquals(2, traversal1.getSteps().size()); t = traversal1.toList(); Assert.assertEquals(2, traversal1.getSteps().size()); Assert.assertEquals(3, t.size()); Assert.assertTrue(t.remove(c1)); Assert.assertTrue(t.remove(c2)); Assert.assertTrue(t.remove(c3)); DefaultGraphTraversal<Vertex, Vertex> traversal2 = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V(a1).repeat(__.out()).until(__.hasLabel("C")); t = traversal2.toList(); Assert.assertEquals(2, traversal2.getSteps().size()); Assert.assertEquals(3, t.size()); Assert.assertEquals(2, traversal2.getSteps().size()); Assert.assertTrue(t.remove(c1)); Assert.assertTrue(t.remove(c2)); Assert.assertTrue(t.remove(c3)); Assert.assertTrue(t.isEmpty()); DefaultGraphTraversal<Vertex, Vertex> traversal3 = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V(a1).until(__.hasLabel("C")).repeat(__.out()); Assert.assertEquals(2, traversal3.getSteps().size()); t = traversal3.toList(); Assert.assertEquals(2, traversal3.getSteps().size()); Assert.assertEquals(3, t.size()); Assert.assertTrue(t.remove(c1)); Assert.assertTrue(t.remove(c2)); Assert.assertTrue(t.remove(c3)); }