简体   繁体   English

在 ArangoDB 中通过遍历过滤返回组

[英]Filtering a return group by traversal in ArangoDB

I'm in the process of evaluating ArangoDB to be used instead of OrientDB.我正在评估要使用 ArangoDB 来代替 OrientDB。 My dataset is essentially a forest of not-necessarily connected trees (a family tree).我的数据集本质上是一个不必要连接的树的森林(家谱)。

Because the dataset is a directed acyclic graph (a tree), it's always more efficient to walk up the tree looking for something than down the tree.因为数据集是一个有向无环图(一棵树),所以沿着树上走寻找东西总是比沿着树下走更有效。

In earlier versions of OrientDB, before they removed this critical feature for me, I was able to do the following query:在 OrientDB 的早期版本中,在他们为我删除这个关键特性之前,我能够执行以下查询:

SELECT FROM Person WHERE haircolor = "Red" and in traverse(0, -1, "in") (birth_country = "Ireland") SELECT FROM Person WHERE haircolor = "Red" and in traverse(0, -1, "in") (birth_country = "Ireland")

Since haircolor is an indexed field, it's efficient to get all of those vertices.由于 haircolor 是一个索引字段,因此获取所有这些顶点是有效的。 The magic is in the traverse operator within the WHERE clause, which stops traversal and immediately returns TRUE if it locates any ancestor from Ireland.神奇之处在于 WHERE 子句中的遍历运算符,如果它找到来自爱尔兰的任何祖先,它会停止遍历并立即返回 TRUE。

Yes, you can turn it around and look for all those from Ireland, and then walk downward looking for those pesky redheads, returning them, but it is substantially less efficient, since you have to evaluate every downward path, which potentially expands exponentially.是的,你可以把它转过来,寻找所有来自爱尔兰的人,然后向下走,寻找那些讨厌的红发女郎,将它们归还,但它的效率要低得多,因为你必须评估每条向下的路径,这可能会呈指数级增长。

Since OrientDB shot themselves in the foot (in my opinion) by taking that feature out, I'm wondering if there's an ArangoDB query that would do a similar task without walking down the tree.由于 OrientDB 通过删除该功能(在我看来)自取其辱,我想知道是否有一个 ArangoDB 查询可以在不走下树的情况下执行类似的任务。

Thanks in advance for your help!在此先感谢您的帮助!

In AQL, it would go something like this:在 AQL 中,它会 go 是这样的:

FOR redhead IN Person                             // Find start vertices
  FILTER doc.haircolor == "Red"
  FOR v, e, p IN 1..99 INBOUND redhead Ancestor   // Traversal up to depth 99
    PRUNE v.birth_country == "Ireland"            // Don't walk further if condition is met
    RETURN p                                      // Return the entire path

This assumes that the relations (edges) are stored in an edge collection called Ancestor .这假设关系(边)存储在名为Ancestor的边集合中。

PRUNE prevents further traversal down (or here: up) the path but includes the node that it is at. PRUNE防止进一步向下(或此处:向上)路径遍历,但包括它所在的节点。 https://www.arangodb.com/docs/stable/aql/graphs-traversals.html#pruning https://www.arangodb.com/docs/stable/aql/graphs-traversals.html#pruning

Note that the variable depth traversal returns not only the longest paths but also "intermediate" paths of the same route.请注意,可变深度遍历不仅返回最长路径,还返回同一路线的“中间”路径。 You may want to filter them out on the client-side or take a look at this AQL solution at the cost of additional traversals: https://stackoverflow.com/a/64931939/2044940您可能希望在客户端将它们过滤掉,或者以额外的遍历为代价查看此 AQL 解决方案: https://stackoverflow.com/a/64931939/2044940

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

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