use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRangeLimit method testRangeRepeatOut.
@Test
public void testRangeRepeatOut() {
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> g = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").repeat(__.out()).times(2).order().by("age").range(10, 20);
Assert.assertEquals(5, g.getSteps().size());
ensureRangeGlobal(g);
List<Vertex> vertexList = g.toList();
Assert.assertEquals(1, 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);
ensureNoRangeGlobal(g);
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);
}
}
use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRangeLimit method testRangeBoth.
@Test
public void testRangeBoth() {
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> g = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("B").both().order().by("age").range(10, 20);
Assert.assertEquals(5, g.getSteps().size());
ensureRangeGlobal(g);
List<Vertex> vertexList = g.toList();
Assert.assertEquals(1, 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);
// cannot be done in SQL
// ensureRangeGlobal(g);
Assert.assertEquals(10, vertexList.size());
for (Vertex v : vertexList) {
Assert.assertTrue(v.label().equals("A") || v.label().equals("C"));
int i = (Integer) v.property("age").value();
Assert.assertTrue(String.valueOf(i), i >= 5 && i < 10);
}
}
use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRangeLimit method testRangeOnVertexLabelsCriteria.
@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"));
}
use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRangeLimit method testSkipAfterNonOptimizedStep.
@Test
public void testSkipAfterNonOptimizedStep() {
for (int i = 0; i < 100; i++) {
Vertex column = this.sqlgGraph.addVertex(T.label, "BigData.Column");
Vertex tag = this.sqlgGraph.addVertex(T.label, "BigData.Tag", "name", "NonAnonymized");
tag.addEdge("tag", column);
}
for (int i = 0; i < 100; i++) {
Vertex column = this.sqlgGraph.addVertex(T.label, "BigData.Column");
Vertex tag = this.sqlgGraph.addVertex(T.label, "BigData.Tag", "name", "Anonymized");
tag.addEdge("tag", column);
}
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("BigData.Column").where(__.in("tag").hasLabel("BigData.Tag").has("name", "Anonymized")).skip(2);
Assert.assertEquals(4, traversal.getSteps().size());
List<Vertex> vertices = traversal.toList();
Assert.assertEquals(3, traversal.getSteps().size());
Assert.assertTrue(traversal.getSteps().get(0) instanceof SqlgGraphStep);
SqlgGraphStep sqlgGraphStep = (SqlgGraphStep) traversal.getSteps().get(0);
assertStep(sqlgGraphStep, true, false, false, true, true);
Assert.assertEquals(98, vertices.size());
}
use of org.umlg.sqlg.step.SqlgGraphStep in project sqlg by pietermartin.
the class TestRangeLimit method testRangeWithNoOrder.
@Test
public void testRangeWithNoOrder() {
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("B").both().limit(10);
Assert.assertEquals(4, traversal.getSteps().size());
List<Vertex> vertices = 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, true, true, false);
Assert.assertEquals(10, vertices.size());
}
Aggregations