Orientdb: Filter on properties of nested relationships

Created on 20 May 2015  Â·  5Comments  Â·  Source: orientechnologies/orientdb

I have a query like the following:

SELECT $a.b, $a.c, $a.out('r3').e, $a.out('r3').f from classD
LET $a=out('r').in('r2')
WHERE field='abc' and $a.out_r3.some_field = 'some_value' OR ( $a.some_field IS NULL)

As is evident I use --> out('r3') syntax to access the fields of the attached vertex, and out_r3 syntax to access fields of the Edge.

These syntax work fine in projections but they do not work in the WHERE clause, because the value in $a.out_r3 on return is a collection of all values. I thought the UNWIND operator might help me there but I am not sure.

Example graph for this condition is :

A ---> D <--- C ---> E

I am accessing D, C, E via A's relationships and want to filter on the properties of relationships connecting A & D and C & D.

All changes in syntax are failing, it just returns 0 records.
How to I filter on nested graph relationships?

question

Most helpful comment

Hi @snig-b

V 2.2 is out with the new MATCH statement

http://orientdb.com/docs/last/SQL-Match.html

It was designed specifically to manage this kind of queries.

I'm closing this issue, please feel free to reopen if you need help on that

Thanks

Luigi

All 5 comments

Hi Snigdha,

have you tried with this?

$a.out_r3.some_field contains "some value"

or even better

$a.out("r3").some_field contains "some value"

Luigi

2015-05-20 14:17 GMT+02:00 Snigdha Batra [email protected]:

I have a query like the following:

SELECT $a.b, $a.c, $a.out('r3').e, $a.out('r3').f from classD
LET $a=out('r').in('r2')
WHERE field='abc' and $a.out_r3.some_field = 'some_value' OR (
$a.some_field IS NULL)

As is evident I use --> out('r3') syntax to access the fields of the
attached vertex, and out_r3 syntax to access fields of the Edge.

These syntax work fine in projections but they do not work in the WHERE
clause, because the value in $a.out_r3 on return is a collection of all
values. I thought the UNWIND operator might help me there but I am not sure.

Example graph for this condition is :

A ---> D <--- C ---> E

I am accessing D, C, E via A's relationships and want to filter on the
properties of relationships connecting A & D and C & D.

All changes in syntax are failing, it just returns 0 records.
How to I filter on nested graph relationships?

—
Reply to this email directly or view it on GitHub
https://github.com/orientechnologies/orientdb/issues/4186.

Hey Luigi

Thanks for the response.

Yes I have, that covers a very small use case of checking whether a string type data is present in the resulting collection. That is a condition on the whole record returning me the arrays.

My requirement is to apply the filters before forming the collections.

That is if $a.out("r3") is returning me ['#12:456','#13:4667']

OR $a.out("r3").some_field is returning me ["some_value",..]

Then I want to apply a where clause that let's me choose whether "some_value" containing record would be returned in the result or not. i.e Remove the '#12:456' relationship altogether..

Similar functionality exists in another GraphDB example in MATCH query -

MATCH (a:A)--[b:B]-->(c:C)--[e:E]-->(f:A)
WHERE e.some_field > b.some_field
RETURN a,b,c

The resulting records would not contain that combination that does not satisfy the where condition.

Any update on this?

Ok, I got the problem now.
Right now it's hard to do this with SQL queries, this is why we are implementing a new MATCH statement (https://github.com/orientechnologies/orientdb-docs/blob/master/SQL-Match.md) with the same philosophy of the query you posted as an example

Hi @snig-b

V 2.2 is out with the new MATCH statement

http://orientdb.com/docs/last/SQL-Match.html

It was designed specifically to manage this kind of queries.

I'm closing this issue, please feel free to reopen if you need help on that

Thanks

Luigi

Was this page helpful?
0 / 5 - 0 ratings