OrientDB SQL 检查多对顶点是否相连

OrientDB SQL Check if multiple pairs of vertices are connected

我没能找到 SQL 的答案。

给定顶点对(记录 ID)和它们之间的边类型,我想检查是否所有对都存在。

V1--E1-->V2

V3--E2-->V4

...等等。我想要的答案是 true / false 或类似的东西。必须存在所有连接才能评估为真,因此每对必须至少存在一个边(正确类型)。

伪,问题是:

Does V1 have edge <E1EdgeType> to V2?
AND
Does V3 have edge <E2EdgeType> to V4?
AND
... and so on

有谁知道 orientDB SQL 会是什么来实现这个?

更新

我确实已经有了一种方法来检查已知顶点之间是否存在一条边。它可能也不是很漂亮,但它有效:

SELECT FROM (
    SELECT EXPAND(out('TestEdge')) FROM #12:0
) WHERE @rid=#12:1

如果从#12:0 到#12:1 存在 'TestEdge' 类型的边,这将 return 目标记录 (#12:0)。但是,如果我有其中两个,我如何查询两个查询的一个结果。类似于:

SELECT <something with $c> LET
    $a = (SELECT FROM (SELECT EXPAND(out('TestEdge')) FROM #12:0) WHERE @rid=#12:1)
    $b = (SELECT FROM (SELECT EXPAND(out('AnotherTestEdge')) FROM #12:2) WHERE @rid=#12:3)
    $c = <something that checks that both a and b yield results>

这就是我的目标。如果我以错误的方式解决这个问题,请告诉我。与重复查询相比,我什至不确定合并这样的查询有什么好处。

给定一对顶点,比如#11:0 和#12:0,以下查询将有效地检查是否存在来自#11:0 的 E 类型的边 到#12:0

select from (select @this, out(E) from #11:0 unwind out) where out = #12:0

----+------+-----+-----
#   |@CLASS|this |out  
----+------+-----+-----
0   |null  |#11:0|#12:0
----+------+-----+-----

这非常不雅,我鼓励您考虑在 https://github.com/orientechnologies/orientdb/issues

相应地制定增强请求

结合您想到的布尔测试的一种方法如下所示:

select from 
  (select $a.size() as a, $b.size() as b
   let a=(select count(*) as e from (select out(E) from #11:0 unwind out)
                                     where out = #12:0),
       b=(select count(*) as e from (select out(E) from #11:1 unwind out)
                                     where out = #12:2))
where a > 0 and b > 0

是的,又不雅:-(

以下查询可能对您有用

SELECT eval('sum($a.size(),$b.size())==2') as existing_edges
let $a = ( SELECT from TestEdge where out = #12:0 and in = #12:1 limit 1),
    $b = ( SELECT from AnotherTestEdge where out = #12:2 and in = #12:3 limit 1)

希望对您有所帮助。