If you want the paths between 2 vertices, then you can do:
SELECT $path as path
FROM (
TRAVERSE outE(), inV() FROM #13:1
)
WHERE @rid == '14:2'
This basically goes through the out edges from #13:1, building the path. It will keep only those that end with the rid #14:2. One thing to note is that, it will return several paths, but if 2 two paths share a common track then only one of those will be retrieved (thats a thing with traverse command that for preventing loops and efficiency does that)
If you have further conditions you want to apply to the traversal, you can put them in the WHILE. Say you want to also take into consideration the value of test attribute from the edges:
SELECT $path as path
FROM (
TRAVERSE outE(), inV() FROM #13:1
WHILE (@class == 'V') OR (@class == 'E' AND test == 3)
)
WHERE @rid == '14:2'
Here you need this 2 conditions because you are traversing both vertices and edges, so if its an edge you want to check on test attribute, if its a vertex, no condition, keep traversing.
NOTE:
There's a caveat from Traverse command where you cannot get all the possible paths between 2 vertices (excluding the paths with cicles), because traverse avoids traversing a node more than once, so the $path will only have one path containing the target vertex. Since we were filtering paths checking for the id of the traversed node, we only get one path be cause it doesnt traverse a node more than once. We need a way to find the paths without relying on traversed nodes....
we've got edges! Here is the workaround:
BEGIN;
LET target = SELECT @rid as rid, inE() as ins FROM <target_id>
LET paths = SELECT $path as path
FROM (TRAVERSE outE(), inV() FROM <source_id>)
WHERE @rid in $target['ins'];
if ($paths.size() > 0) {
LET result = SELECT path.append(".inV(").append($target['rid'][0]).append(")") from $paths;
}
if ($paths.size() == 0) {
LET result = SELECT FROM $paths;
}
COMMIT;
RETURN $result;
So we traverse from the source every path, but we filter those that includes the incomming edges from our target. If a path starting from the source includes an incomming edge from the target, its definitely a valid path between both.
Then we do a little trick to include the target vertex in the path so we can return a nice and complete path string.
This will return all paths between the 2 vertices, including the rels. It may be pretty greedy but is the only way i found to get all possible paths.
1
heroin
On
Don't know, if you're still looking for an answer, but you could try smth like this:
select from (traverse * from #13:1 while @rid <> #14:2) where test = 3
If you want the paths between 2 vertices, then you can do:
This basically goes through the out edges from #13:1, building the path. It will keep only those that end with the rid #14:2. One thing to note is that, it will return several paths, but if 2 two paths share a common track then only one of those will be retrieved (thats a thing with traverse command that for preventing loops and efficiency does that)
If you have further conditions you want to apply to the traversal, you can put them in the WHILE. Say you want to also take into consideration the value of test attribute from the edges:
Here you need this 2 conditions because you are traversing both vertices and edges, so if its an edge you want to check on test attribute, if its a vertex, no condition, keep traversing.
NOTE:
There's a caveat from Traverse command where you cannot get all the possible paths between 2 vertices (excluding the paths with cicles), because traverse avoids traversing a node more than once, so the $path will only have one path containing the target vertex. Since we were filtering paths checking for the id of the traversed node, we only get one path be cause it doesnt traverse a node more than once. We need a way to find the paths without relying on traversed nodes....
we've got edges! Here is the workaround:
So we traverse from the source every path, but we filter those that includes the incomming edges from our target. If a path starting from the source includes an incomming edge from the target, its definitely a valid path between both. Then we do a little trick to include the target vertex in the path so we can return a nice and complete path string.
This will return all paths between the 2 vertices, including the rels. It may be pretty greedy but is the only way i found to get all possible paths.