Help needed formulating query/graph traversal

57 views
Skip to first unread message

Mohammad Bhuyan

unread,
May 28, 2013, 1:22:02 AM5/28/13
to orient-...@googlegroups.com
Hi, 

Lets say, I have the following graph,

Comment ( Vertex) ---> Has (Edge ) ----> Endorsement ( Vertex ) <---- Authority ( Edge ) <-----  Author (Vertex )

where both Comment and Author class has "identifier" field.

How do I, given identifier for Comment and identifier for Author, run query to find,

Endorsements which are for a comment Comment ( given, Identifier ) AND authored by a Author ( given: identifier )

Regards,

Mohammad

  

Mohammad Bhuyan

unread,
May 28, 2013, 1:45:28 AM5/28/13
to orient-...@googlegroups.com
Ok, I think this is it,


select from Endorsement where '3b401193-6a3f-4d5c-93ec-637a7fdeaa11' in in.out.uid and 'a05a3754-7d8c-4911-af91-e156ac1b5cc6' in out.in.uid


Next question is then,

Can I specify Class attribute with in out traversal like it can be done with fatten expressions. Ex: in[@Class='Has'] etc.  

Regards,

Mohammad

Mohammad Bhuyan

unread,
May 28, 2013, 1:56:01 AM5/28/13
to orient-...@googlegroups.com
It does :) Apologies for being lazy.

I have thus working: 

select from Endorsement where '3b401193-6a3f-4d5c-93ec-637a7fdeaa11' in in[@Class='Has'].out[@Class='Comment'].uid and 'a05a3754-7d8c-4911-af91-e156ac1b5cc6' in out[@Class='Authority'].in[@Class='Author'].uid

Yingshou Guo

unread,
May 28, 2013, 2:01:42 AM5/28/13
to orient-...@googlegroups.com
You are using an old version of orientdb? In the latest SNAPSHOP version your graph structure should be different and your query will no longer work.


--
 
---
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/groups/opt_out.
 
 

Mohammad Bhuyan

unread,
May 28, 2013, 2:08:33 AM5/28/13
to orient-...@googlegroups.com
Huh! 

I am using 1.4.0 snapshot taken around 3rd April!

You are saying, latest will break my code? :(

Can you point me to appropriate reads so that I can change accordingly.

Thanks,

Mohammad  

Yingshou Guo

unread,
May 28, 2013, 2:27:42 AM5/28/13
to orient-...@googlegroups.com
In the latest snapshot, the property names in "Endorsement" should be "in_Has" and "in_Authority".

if there are no properties set in your "Has" and "Authority" edges, they are direct link from "Comment" and "Author". There are also "out_Has" property in "Comment" and "out_Authority" property in "Author".

If you still need to directly manipulate the link, it should look like:

select from Endorsement where '3b401193-6a3f-4d5c-93ec-637a7fdeaa11' in in_Has.uid and 'a05a3754-7d8c-4911-af91-e156ac1b5cc6' in in_Authority.uid

If there are properties in your "Has" and "Authority" edges, things get complicated and your query should become:

select from Endorsement where '3b401193-6a3f-4d5c-93ec-637a7fdeaa11' in in_Has.out.uid and 'a05a3754-7d8c-4911-af91-e156ac1b5cc6' in in_Authority.out.uid




Mohammad Bhuyan

unread,
May 28, 2013, 2:43:26 AM5/28/13
to orient-...@googlegroups.com
I like it. Cleaner syntax and less typing. Though a bit annoyed by the code breaking change. :P 

But, what I understood is that depending on if edges has properties or not, the underlying graph structure can be different? Any impact of that I need to keep in mind while updating my code?

Thanks. 

Luca Garulli

unread,
May 28, 2013, 5:21:47 AM5/28/13
to orient-database
For this reason we've the out(), in(), outE() and inE() functions:

select from Endorsement where '3b401193-6a3f-4d5c-93ec-637a7fdeaa11' in inE('Has').uid and 'a05a3754-7d8c-4911-af91-e156ac1b5cc6' in inE('Authority').uid

Lvc@

Yingshou Guo

unread,
May 28, 2013, 5:34:38 AM5/28/13
to orient-...@googlegroups.com
Hi Luca,

It seems that you can not project from the in(), inE() function. I can not make the following query work:

select inE("Has").createTime as createTime, @this as Endorsement from Endorsetment ...

However,

select in_Has.createTime as createTime, @this as Endorsement from ...

works for me.

Am I missing something?


Luca Garulli

unread,
May 28, 2013, 6:11:03 AM5/28/13
to orient-database
Hi Yingshou,
are you using last snapshot or the snapshot published on orientdb.org?

Lvc@

Yingshou Guo

unread,
May 28, 2013, 6:16:29 AM5/28/13
to orient-...@googlegroups.com
Hi Luca,

I'm always using the source code from the master branch to build my server.

Amrutha Valli

unread,
Jul 19, 2016, 5:23:08 AM7/19/16
to OrientDB, aqilco...@gmail.com
Reply all
Reply to author
Forward
0 new messages