简体   繁体   English

ArangoDB中的联接遍历对象结果

[英]Join traversal object results in ArangoDB

I am using ArangoDB's traversal object in order to traverse a recursive group membership structure while avoiding following cycles. 我正在使用ArangoDB的遍历对象 ,以便遍历递归组成员资格结构,同时避免后续循环。 There are cases where I need to join the results of two separate traversals. 在某些情况下,我需要将两次遍历的结果合并在一起。 Is there an efficient way to leverage AQL to join the traversal results? 有没有一种有效的方法来利用AQL来加入遍历结果? I'm currently joining the results in memory with javascript. 我目前正在使用javascript将结果加入内存中。

I'd like to explain this using the traversal graph . 我想用遍历图对此进行解释。 We do two traversals in ANY direction, so the number of results is a little bigger. 我们在ANY方向进行两次遍历,因此结果的数量要大一些。 We start it at points that have neighbors in common which will become the result of the join operation. 我们从具有共同点的邻居开始,这将成为联接操作的结果。 One query will look at A and E which should have B in common, but others of the iteration not. 一个查询将查看AE ,这两个查询应共同具有B ,而其他查询则没有。

The basic iteration: 基本迭代:

FOR v IN 1..1 ANY 'circles/A' GRAPH 'traversalGraph' RETURN v._key

Starting from circles/A this results in ["B","G"] , starting from circles/E this results in ["F", "B"] - so its obvious, we should only get "B" as the result of the join. circles/A开始,这将导致["B","G"] ;从circles/E开始,这将导致["F", "B"] -因此,显而易见,我们应该仅将"B"作为结果加入。

Our first possible approach is to use two sub queries and join them using INTERSECTION : 我们第一种可能的方法是使用两个子查询,并使用INTERSECTION它们:

LET firstTraversal = (FOR v IN 1..1 ANY 'circles/A' GRAPH 'traversalGraph' RETURN v)
LET secondTraversal = (FOR v IN 1..1 ANY 'circles/E' GRAPH 'traversalGraph' RETURN v)
RETURN INTERSECTION(firstTraversal, secondTraversal)

A possible problem here could be, that a full depth comparison of the objects will be done, which may become expensive. 这里可能存在的问题是,将对对象进行完整的深度比较,这可能会变得昂贵。 Another approach therefore could be to join them using their _key attribute: 因此,另一种方法是使用它们的_key属性将它们加入:

LET firstTraversal = (FOR v IN 1..1 ANY 'circles/A' GRAPH 'traversalGraph' RETURN v)
LET secondTraversal = (FOR v IN 1..1 ANY 'circles/E' GRAPH 'traversalGraph' RETURN v)
FOR oneSet IN firstTraversal
  FOR otherSet IN secondTraversal
    FILTER oneSet._key == otherSet._key RETURN oneSet

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

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