Query using out( edge ) function is equals Vertex property

57 views
Skip to first unread message

Rolf Streefkerk

unread,
Aug 26, 2015, 5:20:59 AM8/26/15
to OrientDB
I have the following relationships (where the keywords in CAPS are edges, lowercase keywords are vertices). The dc vertex is the main Object in my model:

dc  -- LOCATED_IN --> city -- LOCATED_IN --> country -- LOCATED_IN --> continent
 
dc -- IS_USED_IN --> project -- IS_OWNED_BY --> user


What I need is for a specific Continent selection (#13:0) all DC's and their Projects owned by User 'X'

So far I tried using LET keyword to unionall queries and expand the result, but I'm not getting the results I want.

I want to have something like this (non working example):

SELECT *, out('IS_USED_IN').include('name') as project FROM dc 
WHERE   
( out(IS_LOCATED_IN).out(IS_LOCATED_IN).out(IS_LOCATED_IN).@rid = #13:0 ) 
AND 
( .out(IS_USED_IN).out(IS_OWNED_BY).name = 'X' )

How can I chain these relationships and query on a specific field? (@rid, name and so on)

Rolf Streefkerk

unread,
Aug 26, 2015, 6:26:05 AM8/26/15
to OrientDB
I tried a bit further with another strategy, not including the user result just yet:

select name, out(IS_USED_IN).include('@rid') as project from 
( select expand( in(LOCATED_IN).in(LOCATED_IN).in(LOCATED_IN) ) from  
( select from #13:0 ) )

now I get a strange result. I expect 2 dc results and one project object per dc. However, for project result I get RID's for; the connected Project (expected) and a city (not expected). 

I guess I'm not there yet?!  What is exactly happening here..

Rolf Streefkerk

unread,
Aug 27, 2015, 2:17:59 AM8/27/15
to OrientDB
Researched further taking into account possible modelling error on my side. So far I cannot see any problems with respect to edge relationships from the Vertex 'dc' (rid: #13:0). 

I think this is a bug, what is happening is it takes all the outgoing edges and returns the result. Instead it should traverse only the out edge "IS_USED_IN".

The version I'm using it OrientDB version : 2.1.0

Rolf Streefkerk

unread,
Aug 27, 2015, 2:41:11 AM8/27/15
to OrientDB
Nevermind, apparently iit is mandatory to put ' quotes around the edge class names but there's no feedback of any error. So it just takes all outgoing edges from class 'dc'. This imo still should not be allowed, is there a strict mode that can be activated?

Luigi Dell'Aquila

unread,
Aug 27, 2015, 3:51:21 AM8/27/15
to orient-...@googlegroups.com
Hi Rolf,

two things here:

1) quotes are generally needed when using out(), in()... functions, eg. out(Friend) is typically an error, while out("Friend") is correct. Anyway, from a technical point of view, out(foo) is not syntactically incorrect, it just means "follow outgoing edges whose class name is the value of 'foo' property in the document itself", eg.

{
 @rid: #12:1
 name: "John",
 out_friend: #12:2,
 out_enemy: #12:3,
 foo: 'friend'
}

select out(foo) from #12:1

is the same as 

select out("friend") from #12:1


2) graph operators like out() return collection values, so you should use CONTAINS operator, not =, eg.

SELECT FROM dc WHERE out(IS_LOCATED_IN).@rid CONTAINS #13:0 

instead of

SELECT FROM dc WHERE out(IS_LOCATED_IN).@rid = #13:0 

Luigi



--

---
You received this message because you are subscribed to the Google Groups "OrientDB" group.
To unsubscribe from this group and stop receiving emails from it, send an email to orient-databa...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Rolf Streefkerk

unread,
Aug 27, 2015, 5:00:17 AM8/27/15
to OrientDB
Thanks Luigi, that makes sense. 

Another thing, is it possible to .include() more fields than just one?

Luigi Dell'Aquila

unread,
Aug 27, 2015, 5:30:49 AM8/27/15
to orient-...@googlegroups.com
Hi Rolf,

yes, you can pass .include() method multiple field names, comma separated

Thanks

Luigi

Rolf Streefkerk

unread,
Aug 27, 2015, 5:35:58 AM8/27/15
to OrientDB
Hi Luigi,

Yes I played around with that, it seems when you do this:

out('IS_USED_IN').include('@rid', 'name')

It will result in just the @rid output and that is all, 'name' will be omitted from the result. @rid seems to be the only column that shows this behavior. Any way around this?

Thanks, Rolf

--

---
You received this message because you are subscribed to a topic in the Google Groups "OrientDB" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/orient-database/kuIzvdXXxEM/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages