Get all ancestors from vector ?

68 views
Skip to first unread message

Sebastien Berthezene

unread,
Oct 2, 2015, 11:38:10 AM10/2/15
to OrientDB
Hi,

I a new to OrientDB then not very comfortable with SQL for graph. How can i get all ancestor from a vertex ? Considering following definitions :

Class Vertex "Folder" extends V,ORestricted
Class Vertex "Document" extends V,ORestricted
Class Edge "HasFolder" extends E
Class E "HasDocument" extends E

I have following graph :
Folder 01 --- [HasFolder]--> Folder 01.01 -- [HasDocument] --> My Doc 01
Folder 01 --- [HasFolder]--> Folder 01.02 -- [HasDocument] --> My Doc 02
Folder 01 --- [HasFolder]--> Folder 02.01 -- [HasDocument] --> My Doc 03
etc...
Starting from "My Doc 01", how can i get all ancestors (Folder 01.01, Folder 01.02) using SQL "traverse" function ? 

SQL : "select from (traverse out() from #<ID Folder>) where @class='Document'" 
Works fine if i want to have all documents referenced into descending tree but do not work if i use "in()" it do not work : "select from (traverse in() from (select from Document where name='My Doc 01'))

I tried with "V.out , E.in" and it do not work also. What is the correct syntax ? I think i miss something :)

Luigi Dell'Aquila

unread,
Oct 5, 2015, 3:37:56 AM10/5/15
to orient-...@googlegroups.com
Hi Sebastien,

it is very strange, your query is correct, so it's supposed to return the right results.
Could you please check if the select subquery returns the right document?

Thanks

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.

Sebastien Berthezene

unread,
Oct 5, 2015, 4:47:39 AM10/5/15
to orient-...@googlegroups.com
I tried using direct ID but not working also :  "select from (traverse in() from #12:14)"

To be clear, i used the studio editor or console to test my query. The result always return the vertex itself and additional column "IN HasDocument" that is the edge i want to traverse back. Basically i can replace the "in()" clause by anything, it always return the same result (ex : select from (traverse dummy from #12:14)).

In general case, what is the query you can use the traverse in reverse way ? In my case, what is the query i can use to at least get all vertex referencing my other vertex from any edge ? And from named edges ? I think i missed  something in the syntax or i do not understand correctly for now.



user.w...@gmail.com

unread,
Oct 5, 2015, 4:56:53 AM10/5/15
to OrientDB
Hi Sebastien,

Can you send me your database (even privately) so I can do more tests?

Regards,
Michela

Luigi Dell'Aquila

unread,
Oct 5, 2015, 4:57:45 AM10/5/15
to orient-...@googlegroups.com
Hi Sebastien,

the syntax is correct, in() operator is the right one.
I think you have some problems in your data. Could you please post result of the following queries?

select from #12:14
select inE() from #12:14
select expand(inE()) from #12:14
select in from #12:14

Thanks

Luigi



--

---
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/3WNJ22S04NY/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-databa...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

Sebastien Berthezene

unread,
Oct 5, 2015, 6:33:04 AM10/5/15
to orient-...@googlegroups.com
I think you are right, it seems to come from my data. When i dump the document #12:14, i have an embedded object "In_HasDocument" pointing to the edge. It is strange and not the case for Folder objects where i can see in and out edges. Here is the way i create this  HasDocument edge (Java) :

Object result = db.command(new OCommandSQL("create EDGE HasDocument from "+folderParent.getIdentity()+" to (select from Document where "+NAME+">='"+fromName+"' and "+NAME+"<='"+toName+"')")).execute();

It must result is a SQL like that :
create EDGE HasDocument from #24:30133 to (select from Document where name >='DOC 000001' and  name <='DOC 000010')

When i create bridges for folders i use :
resultSql = db.command(new OCommandSQL("create EDGE HasFolder from (select from Folder where "+FOLDERPATH+"='"+parentPath+"') to "+result.getIdentity())).execute();

It must result in a SQL like that :
create EDGE HasFolder from (select from Folder where folderpath='/level1/level2') to #24:30133

In this case it works correctly, edges are correctly created for in and out.

I will test again using another way to create edges.

Reply all
Reply to author
Forward
0 new messages