![](/img/trans.png)
[英]OrientDB how to get a result set of vertices and its edges in one query
[英]OrientDB how to get a set of vertices and edges that satisfy a given traverse path?
给出以下图表,我想获得与名为'u0.p1.root.1'的某些子节点相关的所有项目。
要解决先前的请求,我可以运行如下的查询:
select from (
traverse out('rootSphere', 'children')
from (select from V where label = 'project') maxdepth 2
)
where name = 'u0.p0.root.1'
这给了我'u0.p1' 。
问题是我还想获得符合'u0.p1'和'u0.p1.root.1'之间路径的所有顶点和边。
如果我稍微修改查询以获取$ path
select $path from (
traverse out('rootSphere', 'children')
from (select from V where label = 'project') maxdepth 2
)
where name = 'u0.p0.root.1'
然后我明白了
(#9:1030).out[0](#9:1031).out[1](#9:1033)
但我不知道如何处理它:-(
是否可以获得满足给定路径的顶点和边的集合? 有没有更好的查询来解决这个问题?
提前致谢。
看起来你想从u0.p1.root.1向后工作,所以下面的查询可能接近你想要的:
traverse inE('rootSphere', 'children'), outV() from (select from Circle where name='u0.p1.root.1');
(我已将“Circle”这个名字命名为图表中所有圆圈的类。)
当如图所示在图形上运行时,上面的查询产生:
----+-----+----------+------------+-----------+-----+-----+-------------+--------------+-----------+--------------
# |@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]
----+-----+----------+------------+-----------+-----+-----+-------------+--------------+-----------+--------------
在任何情况下,遇到的问题之一是由于out()将输出限制为顶点,而您需要节点和边缘。
您遇到的另一个问题是您使用MAXDEPTH。 关于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必须设置为3才能触及孩子。
在回答有关访问$ 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.