OrientDB how to get the resulting set of vertices and its edges in one query

I played with sql OrientDB queries to get a result set containing not only the vertices, but also the inner edges existing between them.

The request may be expressed as:

  • I want all the vertices associated with project(without the project itself) and all the edges between the vertices included in the results

enter image description here

This is how I achieved it, but I think that this is not the right way to do it.

enter image description here

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 expected results:

enter image description here

Problems with this solution:

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

Is there a better way to solve this use case?

Thanks.

+4
1

:

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)
+4

Source: https://habr.com/ru/post/1618418/


All Articles