简体   繁体   English

AQL(ArangoDb)中的递归遍历

[英]Recursive traversal in AQL (ArangoDb)

When traversing trees or graphs (in my case a DAG), I often see the use for recursion. 遍历树或图(在我的情况下为DAG)时,经常看到递归的用法。 Is this supported or planned to be supported in AQL in the near future? AQL是否支持或计划在不久的将来对此提供支持?

Say I have an AQL query or sub-query (a traversal) and would like to call it recursively. 假设我有一个AQL查询或子查询(遍历),并且想递归调用它。 Could it be done wrapped in Foxx perhaps? 可以用Foxx包装吗?

as things stand there is no recursion in AQL itself. 就目前情况而言,AQL本身没有递归。 Recursion could be wrapped in Foxx using recursion in JavaScript, eg: 可以使用JavaScript中的递归将递归包装在Foxx中,例如:

var recursion = function(last) {
  if (last.length > 3) {
    return last;
  }
  return recursion(db._query("<some AQL query>", {last: last}));
}


controller.get("/recursive", function (req, res) {
  res.json(recursion(["a","b","c"]));
}

For graph traversals we have plans to extend AQL with some operators to define "For All" or "For Any" filters on the traversal path. 对于图遍历,我们计划通过一些运算符扩展AQL,以在遍历路径上定义“全部”或“任何”过滤器。 Which could handle many patters directly. 可以直接处理许多模式。 The syntax will probably look like: 语法可能看起来像:

FOR v,e,p IN 1..12 OUTBOUND "vertex/start" edges
  FILTER p.vertices[*].age ALL >= 35
  RETURN v

Which will than find all paths of length 1 to 12 where all vertices have the age attribute greater or equal to 35 . 然后,它将找到长度为112所有路径,其中所有顶点的age属性大于或等于35

Hope this helps. 希望这可以帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM