简体   繁体   中英

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

I have been playing around with OrientDB sql queries to get a result set that contains not only vertices but also the internal edges that exists between them.

The query could be expressed as:

  • I want all the vertices that are related to project (without project itself) and all the edges between the vertices that are included in the results

在此处输入图片说明

Here is how I have achieved it but I think it is not the proper way to do it.

在此处输入图片说明

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)

And the expected results:

在此处输入图片说明

Problems with this solution:

  • I have to traverse the graph multiple times (first to get the vertices and then to get the edges to finally merge the results)
  • The base query select from V where label = 'project' is also executed several times.

Is there a better way to solve this use case?

Thanks.

Try this query:

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)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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