Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.Traversal#toList()
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.Traversal#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: TestColumnRefactor.java From sqlg with MIT License | 6 votes |
@Test public void testOptionalOptionalLabel() { 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"); 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(); Traversal<Vertex, Vertex> traversal = this.sqlgGraph.traversal().V().hasLabel("A").optional(__.out().optional(__.out())); printTraversalForm(traversal); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(3, vertices.size()); Assert.assertTrue(vertices.contains(a2)); Assert.assertTrue(vertices.contains(b2)); Assert.assertTrue(vertices.contains(c1)); Traversal<Vertex, Path> pathTraversal = this.sqlgGraph.traversal().V().hasLabel("A").optional(__.out().optional(__.out())).path(); printTraversalForm(pathTraversal); List<Path> paths = pathTraversal.toList(); Assert.assertEquals(3, paths.size()); }
Example 2
Source File: BaseTest.java From sqlg with MIT License | 6 votes |
protected static <T> void checkResults(final List<T> expectedResults, final Traversal<?, T> traversal) { final List<T> results = traversal.toList(); Assert.assertFalse(traversal.hasNext()); if (expectedResults.size() != results.size()) { logger.error("Expected results: " + expectedResults); logger.error("Actual results: " + results); Assert.assertEquals("Checking result size", expectedResults.size(), results.size()); } for (T t : results) { if (t instanceof Map) { //noinspection unchecked Assert.assertThat("Checking map result existence: " + t, expectedResults.stream().filter(e -> e instanceof Map).anyMatch(e -> internalCheckMap((Map) e, (Map) t)), CoreMatchers.is(true)); } else { Assert.assertThat("Checking result existence: " + t, expectedResults.contains(t), CoreMatchers.is(true)); } } final Map<T, Long> expectedResultsCount = new HashMap<>(); final Map<T, Long> resultsCount = new HashMap<>(); Assert.assertEquals("Checking indexing is equivalent", expectedResultsCount.size(), resultsCount.size()); expectedResults.forEach(t -> MapHelper.incr(expectedResultsCount, t, 1l)); results.forEach(t -> MapHelper.incr(resultsCount, t, 1l)); expectedResultsCount.forEach((k, v) -> Assert.assertEquals("Checking result group counts", v, resultsCount.get(k))); Assert.assertThat(traversal.hasNext(), CoreMatchers.is(false)); }
Example 3
Source File: OptionalTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(MODERN) public void g_V_optionalXout_optionalXoutXX_path() { final Traversal<Vertex, Path> traversal = get_g_V_optionalXout_optionalXoutXX_path(); printTraversalForm(traversal); List<Path> paths = traversal.toList(); assertEquals(10, paths.size()); List<Predicate<Path>> pathsToAssert = Arrays.asList( p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph, "marko")) && p.get(1).equals(convertToVertex(this.graph, "lop")), p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph, "marko")) && p.get(1).equals(convertToVertex(this.graph, "vadas")), p -> p.size() == 3 && p.get(0).equals(convertToVertex(this.graph, "marko")) && p.get(1).equals(convertToVertex(this.graph, "josh")) && p.get(2).equals(convertToVertex(this.graph, "lop")), p -> p.size() == 3 && p.get(0).equals(convertToVertex(this.graph, "marko")) && p.get(1).equals(convertToVertex(this.graph, "josh")) && p.get(2).equals(convertToVertex(this.graph, "ripple")), p -> p.size() == 1 && p.get(0).equals(convertToVertex(this.graph, "vadas")), p -> p.size() == 1 && p.get(0).equals(convertToVertex(this.graph, "lop")), p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph, "josh")) && p.get(1).equals(convertToVertex(this.graph, "lop")), p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph, "josh")) && p.get(1).equals(convertToVertex(this.graph, "ripple")), p -> p.size() == 1 && p.get(0).equals(convertToVertex(this.graph, "ripple")), p -> p.size() == 2 && p.get(0).equals(convertToVertex(this.graph, "peter")) && p.get(1).equals(convertToVertex(this.graph, "lop")) ); for (Predicate<Path> pathPredicate : pathsToAssert) { Optional<Path> path = paths.stream().filter(pathPredicate).findAny(); assertTrue(path.isPresent()); assertTrue(paths.remove(path.get())); } assertTrue(paths.isEmpty()); }
Example 4
Source File: VertexTest.java From tinkerpop with Apache License 2.0 | 6 votes |
@Test @LoadGraphWith(MODERN) public void g_VX1X_outEXknowsX_bothV_name() { final Traversal<Vertex, String> traversal = get_g_VX1X_outEXknowsX_bothV_name(convertToVertexId("marko")); printTraversalForm(traversal); final List<String> names = traversal.toList(); assertEquals(4, names.size()); assertTrue(names.contains("marko")); assertTrue(names.contains("josh")); assertTrue(names.contains("vadas")); names.remove("marko"); assertEquals(3, names.size()); names.remove("marko"); assertEquals(2, names.size()); names.remove("josh"); assertEquals(1, names.size()); names.remove("vadas"); assertEquals(0, names.size()); }
Example 5
Source File: HasTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_hasXlabel_isXsoftwareXX() { final Traversal<Vertex, Vertex> traversal = get_g_V_hasXlabel_isXsoftwareXX(); printTraversalForm(traversal); final List<Vertex> list = traversal.toList(); assertEquals(2, list.size()); for (final Element v : list) { assertEquals("software", v.label()); } }
Example 6
Source File: OrTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_asXaX_orXselectXaX_selectXaXX() { final Traversal<Vertex, Vertex> traversal = get_g_V_asXaX_orXselectXaX_selectXaXX(); printTraversalForm(traversal); final List<Vertex> actual = traversal.toList(); assertEquals(6, actual.size()); }
Example 7
Source File: TestColumnRefactor.java From sqlg with MIT License | 5 votes |
@Test public void testOptionalLabel() { 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(); Traversal<Vertex, Vertex> traversal = this.sqlgGraph.traversal().V().hasLabel("A").optional(__.out()); printTraversalForm(traversal); List<Vertex> vertices = traversal.toList(); Assert.assertEquals(2, vertices.size()); Assert.assertTrue(vertices.contains(b1)); Assert.assertTrue(vertices.contains(a2)); }
Example 8
Source File: HasTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_hasXage_gt_30X() { final Traversal<Vertex, Vertex> traversal = get_g_V_hasXage_gt_30X(); printTraversalForm(traversal); final List<Vertex> list = traversal.toList(); assertEquals(2, list.size()); for (final Element v : list) { assertTrue(v.<Integer>value("age") > 30); } }
Example 9
Source File: TailTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Scenario: Local scope, List input, default N=1 */ @Test @LoadGraphWith(MODERN) public void g_V_asXaX_out_asXaX_out_asXaX_selectXmixed_aX_byXunfold_valuesXnameX_foldX_tailXlocalX() { final Traversal<Vertex, String> traversal = get_g_V_asXaX_out_asXaX_out_asXaX_selectXmixed_aX_byXunfold_valuesXnameX_foldX_tailXlocalX(); printTraversalForm(traversal); final Set<String> expected = new HashSet(Arrays.asList("ripple", "lop")); final Set<String> actual = new HashSet(traversal.toList()); assertEquals(expected, actual); }
Example 10
Source File: DedupTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_outE_asXeX_inV_asXvX_selectXeX_order_byXweight_ascX_selectXvX_valuesXnameX_dedup() { final Traversal<Vertex, String> traversal = get_g_V_outE_asXeX_inV_asXvX_selectXeX_order_byXweight_ascX_selectXvX_valuesXnameX_dedup(); printTraversalForm(traversal); final List<String> names = traversal.toList(); assertEquals(4, names.size()); assertTrue(names.contains("vadas")); assertTrue(names.contains("lop")); assertTrue(names.contains("josh")); assertTrue(names.contains("ripple")); assertFalse(traversal.hasNext()); }
Example 11
Source File: SparkSingleIterationStrategyTest.java From tinkerpop with Apache License 2.0 | 5 votes |
private static <R> void test(boolean singleIteration, R expectedResult, final Traversal<?, R> traversal) { traversal.asAdmin().applyStrategies(); final Map<String, Object> configuration = TraversalHelper.getFirstStepOfAssignableClass(TraversalVertexProgramStep.class, traversal.asAdmin()).get() .getComputer() .getConfiguration(); assertEquals(singleIteration, configuration.getOrDefault(Constants.GREMLIN_SPARK_SKIP_PARTITIONER, false)); assertEquals(singleIteration, configuration.getOrDefault(Constants.GREMLIN_SPARK_SKIP_GRAPH_CACHE, false)); final List<R> result = traversal.toList(); if (null != expectedResult) assertEquals(expectedResult, result.get(0)); }
Example 12
Source File: VertexTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_VX4X_bothE_hasXweight_lt_1X_otherV() { final Traversal<Vertex, Vertex> traversal = get_g_VX4X_bothE_hasXweight_lt_1X_otherV(convertToVertexId("josh")); printTraversalForm(traversal); final List<Vertex> vertices = traversal.toList(); assertEquals(1, vertices.size()); assertEquals(vertices.get(0).value("name"), "lop"); assertFalse(traversal.hasNext()); }
Example 13
Source File: TestPropertyValues.java From sqlg with MIT License | 5 votes |
@Test public void testOptimizePastSelect() { 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"); Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "name", "b2"); Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "name", "c1"); Vertex c2 = this.sqlgGraph.addVertex(T.label, "C", "name", "c2"); Vertex d1 = this.sqlgGraph.addVertex(T.label, "D", "name", "d1", "surname", "s1"); Vertex d2 = this.sqlgGraph.addVertex(T.label, "D", "name", "d2", "surname", "s2"); a1.addEdge("ab", b1); a2.addEdge("ab", b2); b1.addEdge("bc", c1); b2.addEdge("bc", c2); c1.addEdge("cd", d1); c2.addEdge("cd", d2); this.sqlgGraph.tx().commit(); Traversal<Vertex, String> traversal = this.sqlgGraph.traversal() .V().hasLabel("C") .has("name", "c2") .as("c") .in("bc") .in("ab") .has("name", "a2") .select("c") .out("cd") .has("name", "d2") .values("surname"); printTraversalForm(traversal); List<String> surnames = traversal.toList(); Assert.assertEquals(1, surnames.size()); Assert.assertEquals("s2", surnames.get(0)); checkRestrictedProperties(SqlgVertexStep.class, traversal, 0, "surname"); }
Example 14
Source File: TailTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Scenario: Local scope, Map input, N=1 */ @Test @LoadGraphWith(MODERN) public void g_V_asXaX_out_asXbX_out_asXcX_selectXa_b_cX_byXnameX_tailXlocal_1X() { final Traversal<Vertex, Map<String, String>> traversal = get_g_V_asXaX_out_asXbX_out_asXcX_selectXa_b_cX_byXnameX_tailXlocal_1X(); printTraversalForm(traversal); final Set<Map<String, String>> expected = new HashSet(makeMapList(1, "c", "ripple", "c", "lop")); final Set<Map<String, String>> actual = new HashSet(traversal.toList()); assertEquals(expected, actual); }
Example 15
Source File: DedupTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_both_both_dedup_byXlabelX() { final Traversal<Vertex, Vertex> traversal = get_g_V_both_both_dedup_byXlabelX(); printTraversalForm(traversal); final List<Vertex> vertices = traversal.toList(); assertEquals(2, vertices.size()); }
Example 16
Source File: PageRankTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_pageRank_order_byXpageRank_descX_name_limitX2X() { final Traversal<Vertex, String> traversal = get_g_V_pageRank_order_byXpageRank_descX_name_limitX2X(); printTraversalForm(traversal); final List<String> names = traversal.toList(); assertEquals(2, names.size()); assertEquals("lop", names.get(0)); assertEquals("ripple", names.get(1)); }
Example 17
Source File: RangeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Scenario: limit step, Scope.local, 1 item requested, Map input, Map output */ @Test @LoadGraphWith(MODERN) public void g_V_asXaX_in_asXbX_in_asXcX_selectXa_b_cX_byXnameX_limitXlocal_1X() { final Traversal<Vertex, Map<String, String>> traversal = get_g_V_asXaX_in_asXbX_in_asXcX_selectXa_b_cX_byXnameX_limitXlocal_1X(); printTraversalForm(traversal); final Set<Map<String, String>> expected = new HashSet<>(makeMapList(1, "a", "ripple", "a", "lop")); final Set<Map<String, String>> actual = new HashSet<>(traversal.toList()); assertEquals(expected, actual); }
Example 18
Source File: AndTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_V_asXaX_andXselectXaX_selectXaXX() { final Traversal<Vertex, Vertex> traversal = get_g_V_asXaX_andXselectXaX_selectXaXX(); printTraversalForm(traversal); final List<Vertex> actual = traversal.toList(); assertEquals(6, actual.size()); }
Example 19
Source File: MapTest.java From tinkerpop with Apache License 2.0 | 5 votes |
@Test @LoadGraphWith(MODERN) public void g_VX1X_out_mapXnameX_mapXlengthX() { final Traversal<Vertex, Integer> traversal = get_g_VX1X_out_mapXnameX_mapXlengthX(convertToVertexId("marko")); printTraversalForm(traversal); final List<Integer> lengths = traversal.toList(); assertTrue(lengths.contains("josh".length())); assertTrue(lengths.contains("vadas".length())); assertTrue(lengths.contains("lop".length())); assertEquals(lengths.size(), 3); }
Example 20
Source File: RangeTest.java From tinkerpop with Apache License 2.0 | 5 votes |
/** * Scenario: range step, Scope.local, >1 item requested, List<String> input, List<String> output */ @Test @LoadGraphWith(MODERN) public void g_V_asXaX_out_asXaX_out_asXaX_selectXmixed_aX_byXunfold_valuesXnameX_foldX_rangeXlocal_1_3X() { final Traversal<Vertex, List<String>> traversal = get_g_V_asXaX_out_asXaX_out_asXaX_selectXmixed_aX_byXunfold_valuesXnameX_foldX_rangeXlocal_1_3X(); printTraversalForm(traversal); final Set<List<String>> expected = new HashSet<>(Arrays.asList( Arrays.asList("josh", "ripple"), Arrays.asList("josh", "lop"))); final Set<List<String>> actual = new HashSet(traversal.toList()); assertEquals(expected, actual); }