簡體   English   中英

OrientDB如何獲得滿足給定遍歷路徑的一組頂點和邊?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM