TRAVERSE logic

223 views
Skip to first unread message

Andrey Yesyev

unread,
Feb 19, 2014, 1:12:41 PM2/19/14
to orient-...@googlegroups.com
Hi there,

I was playing with traverse and couldn't figure out the logic of WHILE.
This is what I found in docs:

while condition to continue the traversing while it's true. Usually it's used to limit the traversing depth by using $depth < <x> where x is the maximum level of depth you want to reach. $depth is the first context variable that reports the depth level during traversal. 
Pretty straight forward, but then I tried to query DB

select from ( traverse out_HAS from #12:0 while $depth < 2)

Got the result


@rid@version@classnamein_HASout_HAS
#12:07Casedemo[1][5]
#13:02Collectiongmail_with_attachments.pcap[1]
#13:12Collectionmysql_import_cc.pcap[1]
#13:22Collectionmysql_import_emails.pcap[1]
#13:32Collectiontelnet_cat_emial_list.pcap[1]
#13:42Collectiondemo_stream[1]
Which is perfectly correct.
Now I want to stop traversing, as soon as I reach vertex with the name=gmail_with_attachments.pcap. I assume it should look like this

select from ( traverse out_HAS from #12:0 while $depth < 2 and $current.name <> 'gmail_with_attachments.pcap')

But no, it doesn't work. I'm getting

No records found.

What's the problem?

-Andrey



Luca Garulli

unread,
Feb 19, 2014, 4:47:38 PM2/19/14
to orient-database
Have you tried:

select from ( traverse out_HAS from #12:0 while $depth < 2 and name <> 'gmail_with_attachments.pcap')

Lvc@



--
 
---
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.

Andrey Yesyev

unread,
Feb 19, 2014, 5:30:49 PM2/19/14
to orient-...@googlegroups.com
Oh, yes I did. Forgot to mention,
In this case the result is very unexpected

@rid @version @class name in_HAS out_HAS
#12:0 7 Case demo [1] [5]
#13:1 2 Collection mysql_import_cc.pcap [1]
#13:2 2 Collection mysql_import_emails.pcap [1]
#13:3 2 Collection telnet_cat_emial_list.pcap [1]
#13:4 2 Collection demo_stream [1]
So, I see everything BUT gmail_with_attachments.pcap vertex.




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

Luca Garulli

unread,
Feb 19, 2014, 5:44:53 PM2/19/14
to orient-database
So is it ok, right?

Lvc@

Dexter Pratt

unread,
Feb 19, 2014, 5:58:46 PM2/19/14
to orient-...@googlegroups.com
I think that Andrey's point is that he is expecting "while" to have semantics like a "while" construct in Java - discontinue execution if the condition is not met.

This result excludes the case where the "while" is not satisfied but continues.

(I'm just trying to help clarify, I don't have any opinion about that expectation)  :-)

- Dexter

Dexter Pratt
Director, NDEx project
Ideker Lab UCSD / Cytoscape Consortium

Andrey Yesyev

unread,
Feb 20, 2014, 9:43:08 AM2/20/14
to orient-...@googlegroups.com
Luca - no, it's not ok, from my point of view.

Dexter - thanks, that's exactly what I'm expecting. My expectation is based on this piece of documentation while condition to continue the traversing while it's true.

Am I missing something?

-Andrey

Andrey Yesyev

unread,
Feb 20, 2014, 9:47:58 AM2/20/14
to orient-...@googlegroups.com
I found another piece of documentation https://github.com/orientechnologies/orientdb/wiki/Java-Traverse

Looks like WHILE in TRAVERSE works as a predicate, described in link above. Which completely contradict to the description on this page https://github.com/orientechnologies/orientdb/wiki/SQL-Traverse

Andrey Yesyev

unread,
Feb 20, 2014, 1:16:22 PM2/20/14
to orient-...@googlegroups.com
Dexter,

Is there any way to stop traversing?

-Andrey

Dexter Pratt

unread,
Feb 20, 2014, 1:44:42 PM2/20/14
to orient-...@googlegroups.com
Sorry, this question hasn't come up in our application yet, so I don't know.

- Dexter

Andrey Yesyev

unread,
Feb 20, 2014, 5:18:00 PM2/20/14
to orient-...@googlegroups.com
Ok.
Thanks anyway for your clarifications!

-Andrey

Andrey Yesyev

unread,
Feb 21, 2014, 11:48:25 PM2/21/14
to orient-...@googlegroups.com
Ok, looks like orientdb developers lost their interest in this topic.
But I'm still looking for an answer here.
So, if WHILE works as a predicate and just add a Vertex to result if the condition is true then why this query

select from ( traverse out_HAS from #12:0 while $depth < 2 and name <> 'gmail_with_attachments.pcap')

returns everything, but gmail_with_attachments.pcap 

but this one

select from ( traverse out_HAS from #12:0 while $depth < 2 and name = 'gmail_with_attachments.pcap')

Does not return anything!? Following the predicate logic, it should return a Vertex with name gmail_with_attachments.pcap , doesn't it?

Please explain what's going on here!
Am I missing something!?

-Andrey

PS
Also, if WHILE does follow predicate logic, please correct documentation. It's super confusing...
To unsubscribe from this group and stop receiving emails from it, send an email to orient-database+unsubscribe@googlegroups.com.

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

--
 
---
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/Fvf-4LibdMs/unsubscribe.
To unsubscribe from this group and all its topics, send an email to orient-database+unsubscribe@googlegroups.com.

Luca Garulli

unread,
Feb 22, 2014, 8:58:09 AM2/22/14
to orient-database
Hi guys,
dunno why it's not clear. WHILE condition is exactly like in Java: while the condition is TRUE the traversing continues. As soon as the condition is FALSE traverse stops.

Your result seems correct. The first query:

select from ( traverse out_HAS from #12:0 while $depth < 2)

Returned
And this query:
select from ( traverse out_HAS from #12:0 while $depth < 2 and name <> 'gmail_with_attachments.pcap')

Returned:
And this is the expected result: like the first query but you've added the condition name <> 'gmail_with_attachments.pcap' so the record #13:0 is not part of result set and the traversing under that record is forbidden.

Lvc@

Alan Johnson

unread,
Feb 24, 2014, 9:26:51 PM2/24/14
to orient-...@googlegroups.com
I sounds like the OP wants the predicate based on name to somehow augment the depth conditional, such that when either the depth is reach OR the name is hit the while is ended. This presumes some sort of ordering exists, in that the name element is somehow nested in a manner consistent with or superior to the depth element. Sounds like there is a need for some logic that says the name condition being met constitutes a "break" condition for the while, as in a goto that jumps out of the loop?

Andrey Yesyev

unread,
Feb 25, 2014, 3:23:59 PM2/25/14
to orient-...@googlegroups.com
The only thing I want is to understand how it's supposed to work.
For now, I have two answers, that contradicts each other

First

think that Andrey's point is that he is expecting "while" to have semantics like a "while" construct in Java - discontinue execution if the condition is not met.
This result excludes the case where the "while" is not satisfied but continues.
(I'm just trying to help clarify, I don't have any opinion about that expectation)  :-)
- Dexter

Second

Hi guys,
dunno why it's not clear. WHILE condition is exactly like in Java: while the condition is TRUE the traversing continues. As soon as the condition is FALSE traverse stops.

So it DOES or DOES NOT work as in Java?

-Andrey

Dexter Pratt

unread,
Feb 25, 2014, 4:26:22 PM2/25/14
to orient-...@googlegroups.com
My understanding now is that it works as a Java "while" for the current traversal from a starting point.

The query, however, is the union of all possible traversals from the starting points.

Suppose we have a network that is the union of these paths:

A -> B -> C
A -> B -> D
A -> E -> C

if I traverse with "while not B", then I get to C2 but not to C1 or D - the "while" fails when the traversal encounters B

if I traverse with "while not C" , I get to D.

Or better stated, in the depth-first search, the "while" condition prunes branches of the search tree.



- Dexter

Dexter Pratt
Director, NDEx project
Ideker Lab UCSD / Cytoscape Consortium

Reply all
Reply to author
Forward
0 new messages