Java Code Examples for org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal#next()
The following examples show how to use
org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal#next() .
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: TestVertexStepPerformance.java From sqlg with MIT License | 6 votes |
public void testGroup() { loadGratefulDead(); for (int i = 0; i < 10000; i++) { StopWatch stopWatch = new StopWatch(); stopWatch.start(); DefaultGraphTraversal<Vertex, Map<String, Map<String, Number>>> traversal = (DefaultGraphTraversal<Vertex, Map<String, Map<String, Number>>>) this.sqlgGraph.traversal() .V() .out("followedBy") .<String, Map<String, Number>>group() .by("songType") .by( __.bothE() .group() .by(T.label) .by( __.values("weight").sum() ) ); final Map<String, Map<String, Number>> map = traversal.next(); stopWatch.stop(); System.out.println(stopWatch.toString()); } }
Example 2
Source File: TestGremlinCompileWithHas.java From sqlg with MIT License | 6 votes |
@Test public void g_V_asXaX_out_asXaX_out_asXaX_selectXaX_byXunfold_valuesXnameX_foldX_rangeXlocal_1_2X() { loadModern(); Graph g = this.sqlgGraph; assertModernGraph(g, true, false); DefaultGraphTraversal<Vertex, String> traversal = (DefaultGraphTraversal<Vertex, String>) g.traversal() .V().as("a") .out().as("a") .out().as("a") .<List<String>>select(Pop.all, "a") .by(__.unfold().values("name").fold()) .<String>range(Scope.local, 1, 2); Assert.assertEquals(5, traversal.getSteps().size()); int counter = 0; while (traversal.hasNext()) { final String s = traversal.next(); Assert.assertEquals("josh", s); counter++; } Assert.assertEquals(2, counter); Assert.assertEquals(3, traversal.getSteps().size()); }
Example 3
Source File: TestGremlinCompileWithHas.java From sqlg with MIT License | 6 votes |
@Test public void g_V_asXaX_out_asXaX_out_asXaX_selectXaX_byXunfold_valuesXnameX_foldX_rangeXlocal_1_2X_Simple() { loadModern(); Graph g = this.sqlgGraph; assertModernGraph(g, true, false); DefaultGraphTraversal<Vertex, List<Vertex>> traversal = (DefaultGraphTraversal<Vertex, List<Vertex>>) g.traversal() .V().as("a") .out().as("a") .out().as("a") .<List<Vertex>>select(Pop.all, "a"); Assert.assertEquals(4, traversal.getSteps().size()); printTraversalForm(traversal); Assert.assertEquals(2, traversal.getSteps().size()); int counter = 0; while (traversal.hasNext()) { final List<Vertex> s = traversal.next(); Assert.assertEquals(3, s.size()); System.out.println(s); counter++; } Assert.assertEquals(2, counter); }
Example 4
Source File: TestGremlinCompileWithHas.java From sqlg with MIT License | 6 votes |
@Test public void testg_EX11X_outV_outE_hasXid_10AsStringX() { Graph g = this.sqlgGraph; loadModern(this.sqlgGraph); assertModernGraph(g, true, false); final Object edgeId11 = convertToEdgeId(this.sqlgGraph, "josh", "created", "lop"); final Object edgeId10 = convertToEdgeId(this.sqlgGraph, "josh", "created", "ripple"); DefaultGraphTraversal<Edge, Edge> traversal = (DefaultGraphTraversal<Edge, Edge>) g.traversal().E(edgeId11.toString()) .outV().outE().has(T.id, edgeId10.toString()); Assert.assertEquals(4, traversal.getSteps().size()); printTraversalForm(traversal); Assert.assertEquals(1, traversal.getSteps().size()); Assert.assertTrue(traversal.hasNext()); final Edge e = traversal.next(); Assert.assertEquals(edgeId10.toString(), e.id().toString()); Assert.assertFalse(traversal.hasNext()); }
Example 5
Source File: TestGremlinCompileWithHas.java From sqlg with MIT License | 6 votes |
@Test public void testX() { Graph g = this.sqlgGraph; loadModern(this.sqlgGraph); assertModernGraph(g, true, false); final Object marko = convertToVertexId("marko"); DefaultGraphTraversal<Vertex, Edge> traversal = (DefaultGraphTraversal<Vertex, Edge>) g.traversal().V(marko) .outE("knows").has("weight", 1.0d).as("here").inV().has("name", "josh").<Edge>select("here"); Assert.assertEquals(6, traversal.getSteps().size()); printTraversalForm(traversal); Assert.assertEquals(3, traversal.getSteps().size()); Assert.assertTrue(traversal.hasNext()); Assert.assertTrue(traversal.hasNext()); final Edge edge = traversal.next(); Assert.assertEquals("knows", edge.label()); Assert.assertEquals(1.0d, edge.<Double>value("weight"), 0.00001d); Assert.assertFalse(traversal.hasNext()); Assert.assertFalse(traversal.hasNext()); }
Example 6
Source File: TestTreeStep.java From sqlg with MIT License | 6 votes |
@Test public void testTreeWithSideEffect() { 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); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal() .V().hasLabel("A").out().out().tree("a"); Assert.assertEquals(5, traversal.getSteps().size()); Vertex v = traversal.next(); Assert.assertEquals(2, traversal.getSteps().size()); Assert.assertTrue(Matchers.isOneOf(c1, c2, c3).matches(v)); }
Example 7
Source File: TestGremlinCompileGraphStep.java From sqlg with MIT License | 5 votes |
@Test public void g_V_asXaX_outXcreatedX_inXcreatedX_whereXneqXaXX_asXbX_selectXa_bX_addInEXa_codeveloper_b_year_2009X() throws InterruptedException { Graph g = this.sqlgGraph; loadModern(this.sqlgGraph); assertModernGraph(g, true, false); DefaultGraphTraversal<Vertex, Edge> traversal = (DefaultGraphTraversal<Vertex, Edge>) this.sqlgGraph.traversal() .V().as("a") .out("created") .in("created") .where(P.neq("a")).as("b") .select("a", "b") .addE("co-developer").property("year", 2009).from("a").to("b"); Assert.assertEquals(6, traversal.getSteps().size()); printTraversalForm(traversal); int count = 0; while (traversal.hasNext()) { final Edge edge = traversal.next(); Assert.assertEquals("co-developer", edge.label()); Assert.assertEquals(2009, (int) edge.value("year")); Assert.assertEquals(1, IteratorUtils.count(edge.properties())); Assert.assertEquals("person", edge.inVertex().label()); Assert.assertEquals("person", edge.outVertex().label()); Assert.assertFalse(edge.inVertex().value("name").equals("vadas")); Assert.assertFalse(edge.outVertex().value("name").equals("vadas")); Assert.assertFalse(edge.inVertex().equals(edge.outVertex())); count++; } Assert.assertEquals(4, traversal.getSteps().size()); Assert.assertEquals(6, count); Assert.assertEquals(12, IteratorUtils.count(this.sqlgGraph.edges())); Assert.assertEquals(6, IteratorUtils.count(this.sqlgGraph.vertices())); this.sqlgGraph.tx().commit(); if (this.sqlgGraph1 != null) { Thread.sleep(SLEEP_TIME); Assert.assertEquals(12, IteratorUtils.count(this.sqlgGraph1.edges())); Assert.assertEquals(6, IteratorUtils.count(this.sqlgGraph1.vertices())); } }
Example 8
Source File: TestRangeLimit.java From sqlg with MIT License | 5 votes |
@Test public void testRangeOnMultipleLabels() { for (int i = 0; i < 20; i++) { Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i); Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i); a.addEdge("E", b, "name", "e" + i); } this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>)this.sqlgGraph.traversal() .V().hasLabel("A", "B") .limit(4) .values("name"); Assert.assertEquals(4, g.getSteps().size()); ensureRangeGlobal(g); int cnt = 0; Set<String> names = new HashSet<>(); if (g.hasNext()) { Assert.assertEquals(2, g.getSteps().size()); Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0); //TODO this really should execute limit on the db and finally in the step. //That way less results are returned from the db assertStep(sqlgGraphStep, true, false, true, true, false); } while (g.hasNext()) { String n = (String) g.next(); names.add(n); cnt++; } // we still have to cut the union result // ensureRangeGlobal(g); Assert.assertEquals(4, cnt); Assert.assertEquals(names.toString(), 4, names.size()); }
Example 9
Source File: TestRangeLimit.java From sqlg with MIT License | 5 votes |
@Test public void testRangeOnMultipleLabelsOffset() { for (int i = 0; i < 20; i++) { Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i); Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i); a.addEdge("E", b, "name", "e" + i); } this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>) this.sqlgGraph.traversal() .V().hasLabel("A", "B") .range(1, 4) .values("name"); Assert.assertEquals(4, g.getSteps().size()); ensureRangeGlobal(g); int cnt = 0; Set<String> names = new HashSet<>(); if (g.hasNext()) { Assert.assertEquals(2, g.getSteps().size()); Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0); assertStep(sqlgGraphStep, true, false, true, true, false); } while (g.hasNext()) { String n = (String) g.next(); names.add(n); cnt++; } // cannot have offset on different labels // ensureRangeGlobal(g); Assert.assertEquals(3, cnt); Assert.assertEquals(names.toString(), 3, names.size()); }
Example 10
Source File: TestRangeLimit.java From sqlg with MIT License | 5 votes |
@Test public void testRangeOnEdgeLabels() { for (int i = 0; i < 20; i++) { Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i); Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i); a.addEdge("E", b, "name", "e" + i); } this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Edge, Object> g = (DefaultGraphTraversal<Edge, Object>)this.sqlgGraph.traversal() .E().hasLabel("E") .order().by("name") .range(1, 4) .values("name"); Assert.assertEquals(5, g.getSteps().size()); ensureRangeGlobal(g); int cnt = 0; Set<String> names = new HashSet<>(); String previous = null; if (g.hasNext()) { Assert.assertEquals(2, g.getSteps().size()); Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0); assertStep(sqlgGraphStep, true, false, false, false, true); } while (g.hasNext()) { String n = (String) g.next(); names.add(n); if (previous != null) { Assert.assertTrue(previous.compareTo(n) < 0); } previous = n; cnt++; } ensureNoRangeGlobal(g); Assert.assertEquals(3, cnt); Assert.assertEquals(names.toString(), 3, names.size()); Assert.assertTrue(names.toString(), names.contains("e1")); Assert.assertTrue(names.toString(), names.contains("e10")); Assert.assertTrue(names.toString(), names.contains("e11")); }
Example 11
Source File: TestRangeLimit.java From sqlg with MIT License | 5 votes |
@Test public void testLimitOnVertexLabels() { for (int i = 0; i < 20; i++) { this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i); } this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>)this.sqlgGraph.traversal() .V().hasLabel("A") .order().by("name") .limit(3) .values("name"); Assert.assertEquals(5, g.getSteps().size()); ensureRangeGlobal(g); int cnt = 0; Set<String> names = new HashSet<>(); String previous = null; if (g.hasNext()) { Assert.assertEquals(2, g.getSteps().size()); Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0); assertStep(sqlgGraphStep, true, false, false, false, true); } while (g.hasNext()) { String n = (String) g.next(); names.add(n); if (previous != null) { Assert.assertTrue(previous.compareTo(n) < 0); } previous = n; cnt++; } ensureNoRangeGlobal(g); Assert.assertEquals(3, cnt); Assert.assertEquals(names.toString(), 3, names.size()); Assert.assertTrue(names.toString(), names.contains("a1")); Assert.assertTrue(names.toString(), names.contains("a10")); Assert.assertTrue(names.toString(), names.contains("a0")); }
Example 12
Source File: TestRangeLimit.java From sqlg with MIT License | 5 votes |
@Test public void testRangeOnVertexLabelsNoOrder() { for (int i = 0; i < 20; i++) { this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i); } this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>)this.sqlgGraph.traversal() .V().hasLabel("A") .range(1, 4) .values("name"); Assert.assertEquals(4, g.getSteps().size()); ensureRangeGlobal(g); int cnt = 0; Set<String> names = new HashSet<>(); if (g.hasNext()) { Assert.assertEquals(2, g.getSteps().size()); Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0); assertStep(sqlgGraphStep, true, false, false, true, true); } while (g.hasNext()) { String n = (String) g.next(); names.add(n); cnt++; } ensureNoRangeGlobal(g); Assert.assertEquals(3, cnt); Assert.assertEquals(names.toString(), 3, names.size()); }
Example 13
Source File: TestRangeLimit.java From sqlg with MIT License | 5 votes |
@Test public void testRangeOnVertexLabelsCriteria() { for (int i = 0; i < 100; i++) { this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i, "prop0", "value"); } this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>)this.sqlgGraph.traversal() .V().hasLabel("A").has("prop0", "value") .order().by("name") .range(1, 4) .values("name"); Assert.assertEquals(5, g.getSteps().size()); ensureRangeGlobal(g); int cnt = 0; Set<String> names = new HashSet<>(); String previous = null; if (g.hasNext()) { Assert.assertEquals(2, g.getSteps().size()); Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0); assertStep(sqlgGraphStep, true, false, false, false, true); } while (g.hasNext()) { String n = (String) g.next(); names.add(n); if (previous != null) { Assert.assertTrue(previous.compareTo(n) < 0); } previous = n; cnt++; } ensureNoRangeGlobal(g); Assert.assertEquals(3, cnt); Assert.assertEquals(names.toString(), 3, names.size()); Assert.assertTrue(names.toString(), names.contains("a1")); Assert.assertTrue(names.toString(), names.contains("a10")); Assert.assertTrue(names.toString(), names.contains("a11")); }
Example 14
Source File: TestRangeLimit.java From sqlg with MIT License | 5 votes |
@Test public void testRangeOnVertexLabels() { for (int i = 0; i < 100; i++) { this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i); } this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>)this.sqlgGraph.traversal() .V().hasLabel("A") .order().by("name") .range(1, 4).values("name"); Assert.assertEquals(5, g.getSteps().size()); ensureRangeGlobal(g); int cnt = 0; Set<String> names = new HashSet<>(); String previous = null; if (g.hasNext()) { Assert.assertEquals(2, g.getSteps().size()); Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0); assertStep(sqlgGraphStep, true, false, false, false, true); } while (g.hasNext()) { String n = (String) g.next(); names.add(n); if (previous != null) { Assert.assertTrue(previous.compareTo(n) < 0); } previous = n; cnt++; } ensureNoRangeGlobal(g); Assert.assertEquals(3, cnt); Assert.assertEquals(names.toString(), 3, names.size()); Assert.assertTrue(names.toString(), names.contains("a1")); Assert.assertTrue(names.toString(), names.contains("a10")); Assert.assertTrue(names.toString(), names.contains("a11")); }
Example 15
Source File: TestPathStep.java From sqlg with MIT License | 5 votes |
@Test public void testVertexPathBackToSelf() { Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "a1"); Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "name", "b1"); a1.addEdge("ab", b1); this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Path> gt = (DefaultGraphTraversal<Vertex, Path>) this.sqlgGraph.traversal().V(a1).out().in().path(); Assert.assertEquals(4, gt.getSteps().size()); Path p = gt.next(); Assert.assertEquals(2, gt.getSteps().size()); Assert.assertEquals(3, p.size()); Assert.assertEquals(a1, p.get(0)); Assert.assertEquals(b1, p.get(1)); Assert.assertEquals(a1, p.get(2)); }
Example 16
Source File: TestGremlinCompileWithHas.java From sqlg with MIT License | 5 votes |
@Test public void g_VX1X_outE_hasXweight_inside_0_06X_inV() { Graph g = this.sqlgGraph; loadModern(this.sqlgGraph); assertModernGraph(g, true, false); DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) get_g_VX1X_outE_hasXweight_inside_0_06X_inV(g.traversal(), convertToVertexId("marko")); Assert.assertEquals(4, traversal.getSteps().size()); printTraversalForm(traversal); Assert.assertEquals(1, traversal.getSteps().size()); while (traversal.hasNext()) { Vertex vertex = traversal.next(); Assert.assertTrue(vertex.value("name").equals("vadas") || vertex.value("name").equals("lop")); } Assert.assertFalse(traversal.hasNext()); }
Example 17
Source File: TestGremlinCompileWithHas.java From sqlg with MIT License | 5 votes |
@Test public void g_V_out_outE_inV_inE_inV_both_name() { Graph g = this.sqlgGraph; loadModern(this.sqlgGraph); assertModernGraph(g, true, false); Object id = convertToVertexId(g, "marko"); DefaultGraphTraversal<Vertex, String> traversal = (DefaultGraphTraversal<Vertex, String>) g.traversal().V(id).out().outE().inV().inE().inV().both().<String>values("name"); Assert.assertEquals(8, traversal.getSteps().size()); printTraversalForm(traversal); Assert.assertEquals(2, traversal.getSteps().size()); int counter = 0; final Map<String, Integer> counts = new HashMap<>(); while (traversal.hasNext()) { final String key = traversal.next(); final int previousCount = counts.getOrDefault(key, 0); counts.put(key, previousCount + 1); counter++; } Assert.assertEquals(3, counts.size()); Assert.assertEquals(4, counts.get("josh").intValue()); Assert.assertEquals(3, counts.get("marko").intValue()); Assert.assertEquals(3, counts.get("peter").intValue()); Assert.assertEquals(10, counter); Assert.assertFalse(traversal.hasNext()); }
Example 18
Source File: TestRangeLimit.java From sqlg with MIT License | 4 votes |
@Test public void testRangeOnMultipleLabelsOrdered() { Vertex c = this.sqlgGraph.addVertex(T.label, "C", "name", "c" + 12); for (int i = 0; i < 20; i++) { Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i); Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i); a.addEdge("E", b, "name", "e" + i); } this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>)this.sqlgGraph.traversal() .V().hasLabel("A", "B") .order().by("name") .range(1, 4) .values("name"); Assert.assertEquals(5, g.getSteps().size()); ensureRangeGlobal(g); int cnt = 0; Set<String> names = new HashSet<>(); String previous = null; if (g.hasNext()) { Assert.assertEquals(2, g.getSteps().size()); Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0); assertStep(sqlgGraphStep, true, true, true, true, false); } while (g.hasNext()) { String n = (String) g.next(); names.add(n); if (previous != null) { Assert.assertTrue(previous.compareTo(n) < 0); } previous = n; cnt++; } // order by on multiple labels is not done in SQL, so the range isn't // ensureRangeGlobal(g); Assert.assertEquals(3, cnt); Assert.assertEquals(names.toString(), 3, names.size()); Assert.assertTrue(names.toString(), names.contains("a1")); Assert.assertTrue(names.toString(), names.contains("a10")); Assert.assertTrue(names.toString(), names.contains("a11")); }
Example 19
Source File: TestRangeLimit.java From sqlg with MIT License | 4 votes |
@Test public void testRangeOnMultipleLabelsOrderedWithSkip() { Vertex c = this.sqlgGraph.addVertex(T.label, "C", "name", "c" + 12); for (int i = 0; i < 20; i++) { Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i); Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i); a.addEdge("E", b, "name", "e" + i); } this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>)this.sqlgGraph.traversal() .V().hasLabel("A", "B") .order().by("name") .skip(2) .values("name"); Assert.assertEquals(5, g.getSteps().size()); ensureRangeGlobal(g); int cnt = 0; Set<String> names = new HashSet<>(); String previous = null; if (g.hasNext()) { Assert.assertEquals(2, g.getSteps().size()); Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0); assertStep(sqlgGraphStep, true, true, true, true, false); } while (g.hasNext()) { String n = (String) g.next(); names.add(n); if (previous != null) { Assert.assertTrue(previous.compareTo(n) < 0); } previous = n; cnt++; } // order by on multiple labels is not done in SQL, so the range isn't // ensureRangeGlobal(g); Assert.assertEquals(38, cnt); Assert.assertEquals(names.toString(), 38, names.size()); Assert.assertTrue(names.toString(), !names.contains("a0")); Assert.assertTrue(names.toString(), !names.contains("a1")); }
Example 20
Source File: TestRangeLimit.java From sqlg with MIT License | 4 votes |
@Test public void testRangeOnEdgesOutput() { Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a0"); for (int i = 0; i < 20; i++) { Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i); a.addEdge("E", b, "name", "e" + i); } this.sqlgGraph.tx().commit(); DefaultGraphTraversal<Vertex, Object> g = (DefaultGraphTraversal<Vertex, Object>)this.sqlgGraph.traversal() .V(a) .out("E") .order().by("name") .range(1, 4) .values("name"); Assert.assertEquals(5, g.getSteps().size()); ensureRangeGlobal(g); int cnt = 0; Set<String> names = new HashSet<>(); String previous = null; if (g.hasNext()) { Assert.assertEquals(2, g.getSteps().size()); Assert.assertTrue(g.getSteps().get(0) instanceof SqlgGraphStep); SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) g.getSteps().get(0); assertStep(sqlgGraphStep, true, false, false, false, true); } while (g.hasNext()) { String n = (String) g.next(); names.add(n); if (previous != null) { Assert.assertTrue(previous.compareTo(n) < 0); } previous = n; cnt++; } ensureNoRangeGlobal(g); Assert.assertEquals(3, cnt); Assert.assertEquals(names.toString(), 3, names.size()); Assert.assertTrue(names.toString(), names.contains("b1")); Assert.assertTrue(names.toString(), names.contains("b10")); Assert.assertTrue(names.toString(), names.contains("b11")); }