簡體   English   中英

OrientDB如何在一個查詢中獲得頂點及其邊的結果集

[英]OrientDB how to get a result set of vertices and its edges in one query

我一直在使用OrientDB sql查詢來獲得一個結果集,該結果集不僅包含頂點,而且還包含它們之間存在的內部邊緣。

該查詢可以表示為:

  • 我想要與project相關的所有頂點(沒有項目本身)以及結果中包含的所有頂點之間的邊

在此處輸入圖片說明

這是我實現它的方式,但是我認為這不是正確的方法。

在此處輸入圖片說明

select expand($union) let $vertices = ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ), $edges = ( select from ( select from E where @rid in ( select bothE() from ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) ) ) where out in ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) and in in ( select from ( traverse both() from (select from V where label = 'project') ) skip 1 ) ), $union = unionall($vertices, $edges)

和預期的結果:

在此處輸入圖片說明

該解決方案存在的問題:

  • 我必須遍歷該圖多次(首先獲取頂點,然后獲取邊緣以最終合並結果)
  • 基本查詢select from V where label = 'project'也執行了幾次。

有沒有更好的方法來解決此用例?

謝謝。

試試這個查詢:

select expand($c)
let $a=(traverse both(),bothE() from (select from V where label="project")),
$b=(traverse bothE() from (select from V where label="project")),
$c=difference($a,$b)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

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