我还没能找到SQL的答案。
给出它们之间的顶点对象(记录ID)和边缘类型,我想检查是否所有对都存在。
V1 - E1 - > V2
V3 - E2 - > V4
......等等。我想要的答案是真/假或等同的。必须存在所有连接才能评估为真,因此每对必须至少存在一个(正确类型的)边。
伪,问题是:
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
如果类型为&#39; TestEdge&#39;的边缘,这将返回目标记录(#12:0)。从#12:0到#12:1存在。但是,如果我有两个,那么如何查询两个查询的单个结果。类似的东西:
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>
这就是我的目标。如果我以错误的方式解决这个问题,请告诉我。我甚至不确定将这样的查询合并到仅重复查询的收益是什么。
答案 0 :(得分:2)
给定一对顶点,比如#11:0和#12:0,下面的查询将有效地检查#11中是否存在类型E的边:0 到#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
是的,又不合时宜: - (
答案 1 :(得分:1)
以下查询可能对您有用
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)
希望它有所帮助。