use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestPathStep method testVertexPathWithBy.
@Test
public void testVertexPathWithBy() throws IOException {
Graph graph = this.sqlgGraph;
loadModern(this.sqlgGraph);
assertModernGraph(graph, true, false);
GraphTraversalSource g = graph.traversal();
DefaultGraphTraversal<Vertex, Path> traversal = (DefaultGraphTraversal<Vertex, Path>) g.V(convertToVertexId("marko")).out().path().by("age").by("name");
Assert.assertEquals(3, traversal.getSteps().size());
printTraversalForm(traversal);
Assert.assertEquals(2, traversal.getSteps().size());
int counter = 0;
final Set<String> names = new HashSet<>();
while (traversal.hasNext()) {
counter++;
final Path path = traversal.next();
System.out.println(path);
Assert.assertEquals(Integer.valueOf(29), path.<Integer>get(0));
Assert.assertTrue(path.get(1).equals("josh") || path.get(1).equals("vadas") || path.get(1).equals("lop"));
names.add(path.get(1));
}
Assert.assertEquals(3, counter);
Assert.assertEquals(3, names.size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRangeLimit method testRangeOnVertexLabels.
@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"));
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRangeLimit method testLimitAfterNonOptimizedStep.
@Test
public void testLimitAfterNonOptimizedStep() {
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")).limit(3);
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(3, vertices.size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRangeLimit method testRange.
@Test
public void testRange() {
Vertex a = this.sqlgGraph.addVertex(T.label, "A", "name", "a");
for (int i = 0; i < 10; i++) {
Vertex b = this.sqlgGraph.addVertex(T.label, "B", "name", "b" + i);
a.addEdge("ab", b);
}
this.sqlgGraph.tx().commit();
DefaultGraphTraversal<Vertex, Vertex> traversal = (DefaultGraphTraversal<Vertex, Vertex>) this.sqlgGraph.traversal().V().hasLabel("A").out().range(5, 6);
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, false, true, true);
Assert.assertEquals(1, vertices.size());
}
use of org.apache.tinkerpop.gremlin.process.traversal.dsl.graph.DefaultGraphTraversal in project sqlg by pietermartin.
the class TestRangeLimit method testRangeOnMultipleLabelsOrderedWithSkip.
@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"));
}
Aggregations