简体   繁体   English

OrientDB SQL检查是否连接了多对顶点

[英]OrientDB SQL Check if multiple pairs of vertices are connected

I haven't been able to find an answer for the SQL for this. 我无法为此找到SQL的答案。

Given pairs of vertices (record ids) and edge types between them, I want to check if all pairs exists. 给定成对的顶点(记录ID)和它们之间的边类型,我想检查是否存在所有对顶点。

V1 --E1--> V2 V1 --E1-> V2

V3 --E2--> V4 V3 --E2-> V4

... and so on. ... 等等。 The answer I want is true / false or something equivalent. 我想要的答案是对/错或类似的东西。 ALL connections must be present in order to evaluate to true, so at least one edge (of correct type) must exist for each pair. 必须存在所有连接才能评估为真,因此每对必须至少存在一个边缘(正确类型)。

Pseudo, the question would be: 伪,问题将是:

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

Does anyone know what the orientDB SQL would be to achieve this? 有谁知道实现该目标的orientDB SQL?

UPDATE UPDATE

I did already have one way of checking if one single edge exists between known vertices. 我已经有了一种检查已知顶点之间是否存在单个边的方法。 It's perhaps not very pretty either, but it works: 也许也不是很漂亮,但是它可以工作:

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

This will return the destination record (#12:0) if an edge of type 'TestEdge' exists from #12:0 to #12:1. 如果类型'TestEdge'的边沿存在#12:0到#12:1,则它将返回目标记录(#12:0)。 However, if I have two of those, how can I query for one single result for both queries. 但是,如果我有两个,如何为两个查询都查询一个结果。 Something like: 就像是:

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>

That's what I aim towards doing. 这就是我的目标。 Please tell me if I'm solving this the wrong way. 请告诉我我是否解决错误的方法。 I'm not even sure what the gain is to merge queries like this compared to just repeat queries. 与仅重复查询相比,我什至不确定合并这样的查询有什么好处。

Given a pair of vertices, say #11:0 and #12:0, the following query will effectively check whether there is an edge of type E from #11:0 to #12:0 给定一对顶点(例如#11:0和#12:0),以下查询将有效检查从#11:0到#12:0是否存在类型E的边

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

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

This is highly inelegant and I would encourage you to think about formulating an enhancement request accordingly at https://github.com/orientechnologies/orientdb/issues 这非常不雅致,我鼓励您考虑在https://github.com/orientechnologies/orientdb/issues中相应地提出增强请求

One way to incorporate the boolean tests you have in mind is illustrated by the following: 下面是说明合并布尔测试的一种方法:

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

Yes, inelegance again :-( 是的,再次优雅:-(

It might be useful to you the following query 以下查询可能对您有用

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)

Hope it helps. 希望能帮助到你。

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

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