Don't want all the intermittent parts of traversal

117 views
Skip to first unread message

Martijn Geers

unread,
Nov 19, 2019, 6:11:14 AM11/19/19
to ArangoDB
Hi guys,

I've been playing around with traversals for a bit but there're some things I don't quite seem to understand.
First we have the FOR loop in which we specify a MIN and MAX.
If I, say, specify FOR I IN 1..5, what happens is I get the same path over and over again but cut off at different points.
I'd rather just see the most complete version of that single path and not all the intermittent steps.

In that case one could argue I could do FOR I in 5..5 but I don't necessarily know for each path how long it's going to be a priori.
Is there no way for this to be done dynamically?


Simran Brucherseifer

unread,
Nov 23, 2019, 9:43:58 AM11/23/19
to ArangoDB
You can do a second traversal with depth = 1 to check if you reached a leaf node (no more incoming edges).
Based on this information, the “short” paths can be filtered out.

Note that a second condition is required:
it is possible that the last node in a traversal is not a leaf node if the maximum traversal depth is exceeded.
Thus, you need to also let paths through, which contain as many edges as hops you do in the traversal.

LET maxDepth = 5
FOR v
, e, p IN 1..maxDepth OUTBOUND "verts/s" edges
  LET
next = (
    FOR vv
, ee IN OUTBOUND v edges
     
//FILTER ee != e // needed if traversing edges in ANY direction
      LIMIT
1 // optimization, no need to check for more than a single neighbor
      RETURN
true // using a constant here, which is not actually used
 
)
  FILTER LENGTH
(next) == 0 || LENGTH(p.edges) == maxDepth
  RETURN CONCAT_SEPARATOR
(" <- ", p.vertices[*]._key)

Reply all
Reply to author
Forward
0 new messages