How to traverse verticies using gremlin java and orientdb

730 views Asked by At

I'm new in Graph databases, and i can't resolve problem listed below. How i can implement OrientDb query like TRAVERSE OUT() FROM (SELECT FROM SomeClassThatExtendsV WHERE name = 'SomeUsefulName')

If i will execute this query via OrientDb java api :

new OSQLSynchQuery<Vertex>("TRAVERSE OUT() FROM (SELECT FROM SomeClassThatExtendsV WHERE name = 'SomeUsefulName')");

The result will be all child verticies with child and child and so on.

I need to implement same logic using gremlin api, that's what i have:

    GraphQuery query = framedGraph.getBaseGraph().query().has("@class", "SomeClassThatExtendsV").has("name", "SomeUsefulName");
    OrientVertex vertex = (OrientVertex) query.vertices().iterator().next();
    Tree tree = new Tree();
    new GremlinPipeline(vertex).out().tree(tree).loop("TestLoop", loopBundle -> false).iterate();
    Iterator it = tree.entrySet().iterator();
    while (it.hasNext()) {
        Map.Entry pair = (Map.Entry)it.next();
        System.out.println(pair.getKey() + " = " + pair.getValue());

    }

As result i have NullPointerException.

java.lang.NullPointerException
    at com.tinkerpop.pipes.branch.LoopPipe.getLoops(LoopPipe.java:75)
    at com.tinkerpop.pipes.branch.LoopPipe.processNextStart(LoopPipe.java:49)
    at com.tinkerpop.pipes.AbstractPipe.next(AbstractPipe.java:89)
    at com.tinkerpop.pipes.util.Pipeline.next(Pipeline.java:115)
    at com.tinkerpop.pipes.util.PipeHelper.iterate(PipeHelper.java:35)
    at com.tinkerpop.gremlin.java.GremlinPipeline.iterate(GremlinPipeline.java:1542) 

Maybe i'm doing something wrong in when in GremlinPipeline?

At this point i don't know full graph structure and i need to get something like tree, or something like result in OrientDb studio.

Some update here, i tried to use loop but as i told before i can't setup count of loops and due to this my test application stuck because in some vertices i have in edge and out edge.

Could somebody help me with this problem?

0

There are 0 answers