1
votes

In both Java and SQL I can recurse through a list of Vertices to get all linked nodes. But I can't seem to get the same result when using fetchPlan.

This returns the correct graph (all nodes linked to the parent but not other parents that share the same child node)

traverse out('Dependency') from #33

I am looking for a fetch plan that will return the same graph. Pasted below is a fetchPlan that is close but pulls in other root nodes and I only want all the children of a single parent.

id.getRecord().toJSON("fetchPlan:out_Dependency:6")

My DB has 2 Vertices and 1 Edge connecting them. Parent -> Edge -> Child. A child might be linked to multiple parents but from parent view I only want to see his children not connected Parents.

2

2 Answers

0
votes

Try this:

select @this.toJSON('fetchPlan:out_Dependency:2') from #21:0

this is what I get:

enter image description here

as you can see the query returns me only the linked child and not the other parents.

Hope it helps.

Regards.

0
votes

With javascript you could use this function with the paramenter rid

var g=orient.getGraph();
var nodes = [];
var previous=[];
var currently=[];
var b=g.command("sql","select from " + rid);
if(b.length>0){
    var vertex=b[0];
    previous.push(vertex);
    nodes.push(vertex);
    do{
        for(i=0;i<previous.length;i++){
            var vertexOut=previous[i];
            var vertices=g.command("sql","select expand(out('Dependency')) from "+ vertexOut.getId());
            for(j=0;j<vertices.length;j++){ 
                currently.push(vertices[j]);
                nodes.push(vertices[j]);
            }
        }
        change();
    }while(previous.length>0);
    return nodes;
}

function change(){
    previous=[];
    for (indice=0;indice<currently.length;indice++)
        previous.push(currently[indice]);
    currently=[];
}

Hope it helps