Search code examples
arangodbaql

Arangodb AQL start vertex included despite min depth set to 1


The following traversal always returns the start vertex even though the min depth is set to 1. I would have expected the start vertex to be returned only if the min depth was set to 0. Also interesting is the OPTIONS function does not work with the filters used (error: unexpected identifier near 'OPTIONS { uniqueVertices: "path"...' at position 7:1 (while parsing)). If I run this as two separate queries one each for the vertices and edges I get the expected result.

for v,e,p in 1..2
                outbound 'X/14268273'
                Edge
                        let Coll = (parse_identifier(v._id).collection)
                     filter Coll in (['A', 'B','C', 'D'])
//OPTIONS { uniqueVertices: "path" , bfs: false}
                sort v.order
                return p

Solution

  • You return p, which is the path from the start vertex to the current node. Min depth does not affect it. With a depth of 2..2, it will include the start vertex as well as the vertex at depth 1 and the edge between both of them. The min depth does not make it exclude vertices or edges from the path.

    A min depth of 0 will emit the start vertex as v and null as e on the first "iteration" of the for loop however. Any higher min depth will skip this. Using 1..2 as depths will get you more paths, with shorter versions of the depth 2 paths among them, but always with the start vertex at p.vertices[0].

    Regarding traversal options, the syntax is FOR … IN … OPTIONS. You have to place the independent LET and FILTER operations after OPTIONS which belongs to the traversal language construct.

    If you want to filter out any paths which include a vertex from an unspecified collections, then you need to do that for all vertices on the path, use PRUNE or the upcoming vertexCollections option (3.7). Filtering just on v will not eliminate certain paths (path of depth 2 where the vertex at depth 2 is from collection A, B, C or D, but the vertex at depth 1 is not).