use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRangeLimit method testStepsAfterRangeNotOptimized.
@Test
public void testStepsAfterRangeNotOptimized() {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "name", "d");
Vertex a2 = this.sqlgGraph.addVertex(T.label, "A", "name", "c");
Vertex a3 = this.sqlgGraph.addVertex(T.label, "A", "name", "b");
Vertex a4 = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "surname", "b");
Vertex b2 = this.sqlgGraph.addVertex(T.label, "B", "surname", "b");
Vertex b3 = this.sqlgGraph.addVertex(T.label, "B", "surname", "b");
Vertex b4 = this.sqlgGraph.addVertex(T.label, "B", "surname", "b");
a1.addEdge("ab", b1);
a2.addEdge("ab", b2);
a3.addEdge("ab", b3);
a4.addEdge("ab", b4);
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").order().by("name").limit(2).out("ab");
Assert.assertEquals(5, traversal.getSteps().size());
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
assertStep(sqlgGraphStep, true, false, false, false, true);
Assert.assertEquals(2, vertices.size());
Assert.assertTrue(vertices.contains(b3));
Assert.assertTrue(vertices.contains(b4));
}
use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRangeLimit method testRangeOnMultipleLabelsOffset.
@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());
}
use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRangeLimit method testVWithLimit.
@Test
public void testVWithLimit() {
for (int i = 0; i < 100; i++) {
this.sqlgGraph.addVertex(T.label, "A", "name", "a" + i);
this.sqlgGraph.addVertex(T.label, "B", "name", "a" + i);
}
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().range(1, 2);
ensureRangeGlobal(traversal);
Assert.assertEquals(2, traversal.getSteps().size());
Assert.assertEquals(1, traversal.toList().size());
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
assertStep(sqlgGraphStep, true, false, true, true, false);
}
use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRangeLimit method testRangeOnMultipleLabelsOrdered.
@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"));
}
use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRangeLimit method testRangeOut.
@Test
public void testRangeOut() {
for (int i = 0; i < 100; i++) {
Vertex a1 = this.sqlgGraph.addVertex(T.label, "A", "age", i);
Vertex b1 = this.sqlgGraph.addVertex(T.label, "B", "age", i);
Vertex c1 = this.sqlgGraph.addVertex(T.label, "C", "age", i);
a1.addEdge("ab", b1);
b1.addEdge("bc", c1);
}
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").out().out().order().by("age").range(10, 20);
Assert.assertEquals(6, traversal.getSteps().size());
List<Vertex> vertexList = traversal.toList();
Assert.assertEquals(1, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
assertStep(sqlgGraphStep, true, false, false, false, true);
Assert.assertEquals(10, vertexList.size());
for (Vertex v : vertexList) {
Assert.assertEquals("C", v.label());
int i = (Integer) v.property("age").value();
Assert.assertTrue(i >= 10 && i < 20);
}
}
Aggregations