/**
* Traverse all vertices up until the specified depth. Edges are not returned
* GREMLIN
*/
public void traverseVerticesGremlin(Object vId, int depth, boolean logEnabled) {
Set x = new HashSet<Vertex>(); Set e = new HashSet<Edge>();
new GremlinPipeline<>()
.start(vId)
.as("s1")
.bothE()
.as("e")
.store(e)
.bothV()
.except("s1")
.except(x)
.store(x)
.loop("s1", o -> {
if (logEnabled)
System.out.println(((LoopPipe.LoopBundle) o).getObject().toString());
return ((LoopPipe.LoopBundle) o).getLoops() <= depth;
}).iterate();
edgeCounter = e.size();
vertexCounter = x.size();
}
/**
* Traverse all vertices up until the specified depth. Edges are not returned
* OSQL
*/
public void traverseVerticesOSQL(Object vId, int depth, boolean logEnabled) {
if (queryType.equalsIgnoreCase("osql-traverse")) {
oSqlQuery = "SELECT FROM (traverse * from " + vId + " while $depth <= " + depth + " strategy BREADTH_FIRST) LIMIT -1";
}
((Iterable<Object>) ((OrientGraph) graph).command(new OSQLSynchQuery<>(oSqlQuery)).execute()).forEach(o -> {
if (logEnabled))
System.out.println(o);
if (o.getClass() == OrientVertex.class) vertexCounter++;
else if (o.getClass() == OrientEdge.class) edgeCounter++;
});
}
While the results are the same I see a huge performance drop, when I use Gremlin. The Gremlin command was fully optimised in
discussion with Gremlin guru Daniel Kuppitz.