Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to merge results of two queries in OrientDB

Tags:

sql

orientdb

Let's say I have 4 vertex classes: V1,V2,V3,V4 And also 3 edge classes: E1,E2,E3

Then instances of them are (possibly) connected like this:

V1 --E1--> V2
V2 --E2--> V3
V2 --E3--> V4
V3 --E3--> V4

So, graph-wise something like:

V1---E1---V2
          |   \
          E2    E3
          |        \
          V3---E3---V4

With directions shown above.

I'm now interested in paths over the exact edges shown from V1 to V4 (There might be other edges between them as well that we don't know about, so only the edge types already mentioned are ok.)

To check if one of the paths from V1 to V4 exists (rather V4 will be returned if path exists):

SELECT EXPAND(out('E1').out('E3')) FROM V1 WHERE id = <someIdThatV1Has>

To check if the other path exists (rather V4 will be returned if path exists):

SELECT EXPAND(out('E1').out('E2').out('E3')) FROM V1 WHERE id = <someIdThatV1Has>

The only interest I have is to know if ONE of the two paths exists. I would like to do this with one query.

Question

How can I merge these two queries to one query to find out if one of the two paths exists?

(If possible, a general answer to how to merge different traversal queries in OrientDB along with an explicit answer would be highly appreciated.)

Thanks!

like image 783
dargolith Avatar asked Oct 15 '25 09:10

dargolith


1 Answers

Try with unionAll

select expand($c) 
let $a = ( SELECT EXPAND(out('E1').out('E3')) FROM V1 WHERE id = <someIdThatV1Has>), 
$b = ( SELECT EXPAND(out('E1').out('E2').out('E3')) FROM V1 WHERE id = <someIdThatV1Has>),
$c = unionAll( $a, $b )

You can look the documentation at the following link http://orientdb.com/docs/2.1/SQL.html#select-from-multiple-targets

like image 160
Alessandro Rota Avatar answered Oct 17 '25 00:10

Alessandro Rota



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!