简体   繁体   English

OrientDB如何获得满足给定遍历路径的一组顶点和边?

[英]OrientDB how to get a set of vertices and edges that satisfy a given traverse path?

Given the following graph I want to get all the projects that are related with some children node with name 'u0.p1.root.1' . 给出以下图表,我想获得与名为'u0.p1.root.1'的某些子节点相关的所有项目。

在此输入图像描述

To solve the previous request I can run a query like this one: 要解决先前的请求,我可以运行如下的查询:

select from (
    traverse out('rootSphere', 'children') 
    from (select from V where label = 'project') maxdepth 2
)
where name = 'u0.p0.root.1'

which gives me 'u0.p1' . 这给了我'u0.p1'

The problem is that I also want to get all the vertices and edges that conform the path between 'u0.p1' and 'u0.p1.root.1' 问题是我还想获得符合'u0.p1''u0.p1.root.1'之间路径的所有顶点和边

If I slightly modify the query to get the $path 如果我稍微修改查询以获取$ path

select $path from (
    traverse out('rootSphere', 'children') 
    from (select from V where label = 'project') maxdepth 2
)
where name = 'u0.p0.root.1'

then I get 然后我明白了

(#9:1030).out[0](#9:1031).out[1](#9:1033)

but I don't know how to deal with it :-( 但我不知道如何处理它:-(

Is it possible to get the set of vertices and edges that satisfy the given path? 是否可以获得满足给定路径的顶点和边的集合? is there maybe a better query to solve this problem? 有没有更好的查询来解决这个问题?

Thanks in advance. 提前致谢。

It looks like you want to work backward from u0.p1.root.1, so the following query may be close to what you want: 看起来你想从u0.p1.root.1向后工作,所以下面的查询可能接近你想要的:

traverse inE('rootSphere', 'children'), outV() from (select from Circle where name='u0.p1.root.1');

(I have given the name "Circle" to the class of all circles in your diagram.) (我已将“Circle”这个名字命名为图表中所有圆圈的类。)

When run on the graph as shown in the diagram, the above query produces: 当如图所示在图形上运行时,上面的查询产生:

----+-----+----------+------------+-----------+-----+-----+-------------+--------------+-----------+--------------
#   |@RID |@CLASS    |name        |in_children|out  |in   |in_rootSphere|out_children  |in_projects|out_rootSphere
----+-----+----------+------------+-----------+-----+-----+-------------+--------------+-----------+--------------
0   |#11:3|Circle    |u0.p1.root.1|[#15:3]    |null |null |null         |null          |null       |null          
1   |#15:3|children  |null        |null       |#11:2|#11:3|null         |null          |null       |null          
2   |#11:2|Circle    |u0.p1.root  |null       |null |null |[#14:1]      |[#15:2, #15:3]|null       |null          
3   |#14:1|rootSphere|null        |null       |#11:1|#11:2|null         |null          |null       |null          
4   |#11:1|Circle    |u0.p1       |null       |null |null |null         |null          |[size=1]   |[#14:1]       
----+-----+----------+------------+-----------+-----+-----+-------------+--------------+-----------+--------------

In any case, one of the problems you ran into arises from the fact that out() restricts the output to vertices, whereas you want nodes and edges. 在任何情况下,遇到的问题之一是由于out()将输出限制为顶点,而您需要节点和边缘。

Another problem you encountered is your use of MAXDEPTH. 您遇到的另一个问题是您使用MAXDEPTH。 The OrientDB documentation is not so clear about MAXDEPTH, so consider this query and the results: 关于MAXDEPTH,OrientDB文档还不是很清楚,所以请考虑这个查询和结果:

traverse outE('rootSphere', 'children'), inV() from (select from V where name='u0.p1') maxdepth 3;

----+-----+----------+------------+-----------+--------------+-----+-----+-------------+--------------+-----------
#   |@RID |@CLASS    |name        |in_projects|out_rootSphere|out  |in   |in_rootSphere|out_children  |in_children
----+-----+----------+------------+-----------+--------------+-----+-----+-------------+--------------+-----------
0   |#11:1|Circle    |u0.p1       |[size=1]   |[#14:1]       |null |null |null         |null          |null       
1   |#14:1|rootSphere|null        |null       |null          |#11:1|#11:2|null         |null          |null       
2   |#11:2|Circle    |u0.p1.root  |null       |null          |null |null |[#14:1]      |[#15:2, #15:3]|null       
3   |#15:2|children  |null        |null       |null          |#11:2|#11:4|null         |null          |null       
4   |#11:4|Circle    |u0.p1.root.0|null       |null          |null |null |null         |null          |[#15:2]    
5   |#15:3|children  |null        |null       |null          |#11:2|#11:3|null         |null          |null       
6   |#11:3|Circle    |u0.p1.root.1|null       |null          |null |null |null         |null          |[#15:3]    
----+-----+----------+------------+-----------+--------------+-----+-----+-------------+--------------+-----------

MAXDEPTH must be set to 3 here to reach the children. MAXDEPTH必须设置为3才能触及孩子。

In response to the question about accessing the elements of $path, here is another solution to the original problem that uses an approach that is similar to your query using "$path", but it uses traversedElement instead of $path: 在回答有关访问$ path元素的问题时,这里是原始问题的另一种解决方案,它使用类似于使用“$ path”的查询的方法,但它使用traversedElement而不是$ path:

select expand( traversedElement )
from (select traversedElement(0,100)
      from ( traverse outE('rootSphere', 'children'), inV()
             from Circle)
      where name = 'u0.p1.root.1' ) 

----+-----+----------+------------+-----------+--------------+-----+-----+-------------+--------------+-----------
#   |@RID |@CLASS    |name        |in_projects|out_rootSphere|out  |in   |in_rootSphere|out_children  |in_children
----+-----+----------+------------+-----------+--------------+-----+-----+-------------+--------------+-----------
0   |#11:1|Circle    |u0.p1       |[size=1]   |[#14:1]       |null |null |null         |null          |null       
1   |#14:1|rootSphere|null        |null       |null          |#11:1|#11:2|null         |null          |null       
2   |#11:2|Circle    |u0.p1.root  |null       |null          |null |null |[size=1]     |[#15:2, #15:3]|null       
3   |#15:3|children  |null        |null       |null          |#11:2|#11:3|null         |null          |null       
4   |#11:3|Circle    |u0.p1.root.1|null       |null          |null |null |null         |null          |[size=1]   
----+-----+----------+------------+-----------+--------------+-----+-----+-------------+--------------+-----------

5 item(s) found. Query executed in 0.051 sec(s).

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

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