鉴于以下图表,我想获得与名为'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)
但我不知道如何处理它: - (
是否可以获得满足给定路径的顶点和边集? 有没有更好的查询来解决这个问题?
提前致谢。
答案 0 :(得分:4)
看起来你想从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以接触孩子。
答案 1 :(得分:2)
在回答有关访问$ path元素的问题时,这是原始问题的另一种解决方案,它使用类似于使用" $ path"的查询的方法,但它使用traversedElement代替of $ 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).