简体   繁体   English

如何使用OrientDB fetchPlan返回SQL Traverse

[英]How to use OrientDB fetchPlan to return a SQL Traverse

In both Java and SQL I can recurse through a list of Vertices to get all linked nodes. 在Java和SQL中,我可以通过顶点列表递归以获取所有链接节点。 But I can't seem to get the same result when using fetchPlan. 但是在使用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. 下面粘贴的是一个fetchPlan,它接近但是拉入其他根节点,我只想要单个父节点的所有子节点。

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

My DB has 2 Vertices and 1 Edge connecting them. 我的数据库有2个顶点和1个边连接它们。 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. 一个孩子可能与多个父母有关,但从父母的观点来看,我只想看到他的孩子没有与父母联系。

Try this: 尝试这个:

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

this is what I get: 这就是我得到的:

在此输入图像描述

as you can see the query returns me only the linked child and not the other parents. 正如您所看到的,查询只返回链接的子项而不是其他父项。

Hope it helps. 希望能帮助到你。

Regards. 问候。

With javascript you could use this function with the paramenter rid 使用javascript,您可以使用此功能与参数删除

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 希望能帮助到你

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM