dargolith
dargolith

Reputation: 311

How to merge results of two queries in 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!

Upvotes: 4

Views: 2763

Answers (1)

Alessandro Rota
Alessandro Rota

Reputation: 3570

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

Upvotes: 6

Related Questions