简体   繁体   English

OrientDB如何在一个查询中获得顶点及其边的结果集

[英]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. 我一直在使用OrientDB sql查询来获得一个结果集,该结果集不仅包含顶点,而且还包含它们之间存在的内部边缘。

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 我想要与project相关的所有顶点(没有项目本身)以及结果中包含的所有顶点之间的边

在此处输入图片说明

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. 基本查询select from V where label = 'project'也执行了几次。

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)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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