使用 ArangoDb AQL 过滤不同的图边类型 [英] Filter on different graph edge types using ArangoDb AQL

查看:33
本文介绍了使用 ArangoDb AQL 过滤不同的图边类型的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有以下文档集合:

Assuming I have the following document collections:

  • 有姓名和学生 ID 的学生
  • 具有名称和类 ID 的类
  • 带有名称和位置 ID 的位置

以及以下指定关系的边集合:

and the following edge collections specifying the relationships:

  • 带有 _from 和 _to 引用以及开始和结束日期的学生类
  • 只有 _from 和 _to 引用的类位置

返回给定日期显示班级和位置的学生图表的最佳方法是什么?我一直在使用类似下面的东西,但它返回了不在日期范围内的 StudentClass 边缘.此外,由于过滤器不在路径上,我相信所有边都将被遍历,这意味着这可能无法很好地扩展.

What is the best way to return a graph for a student for a given date showing the classes and locations? I have been using something like the following, but it's returning StudentClass edges that do not fall within the date range. Also, since the filter is not on the path I believe that all edges will be traversed meaning that this may not scale well.

FOR v, e, p
IN 1..10 OUTBOUND "Students/1234"
StudentClass, ClassLocations 
FILTER ((e.endDate > "2017-10-01") AND (e.startDate < "2017-10-01"))
 OR (e.endDate == null)
RETURN p

推荐答案

感谢 mark.arangodb,我已经能够创建一个可行的解决方案:

Thanks to mark.arangodb I've been able to create a working solution:

FOR v, e, p
IN 1..10 OUTBOUND "Students/1234"
StudentClass, ClassLocations 
FILTER p.edges[*].startDate ALL <= @date
LET counter = (FOR e2 IN p.edges 
               FILTER NOT_NULL(e2.endDate, @date) >= @date 
               RETURN e2)
FILTER COUNT(counter) == COUNT(p.edges) 
RETURN p

第一个过滤器确保所有边都必须在@date 绑定参数中给出的日期(作为字符串)之前有一个 startDate.没有 startDate 属性的边通过此过滤器.(ArangoDb 必须将 null 视为小于任何值的值.)

The first filter ensures that all edges must have a startDate prior to the date given (as a string) in the @date bind parameter. An edge without the startDate property passes this filter. (ArangoDb must treat null as a value less than anything.)

LET 语句创建一个名为counter"的变量,并将其分配给一个边数组,这些边的 endDate 大于给定日期或没有 endDate.最终过滤器仅允许具有与counter"变量中的边数相同的边数的路径.

The LET statement creates a variable called "counter" and assigns it to an array of edges that either have an endDate greater than the given date or that don't have an endDate. The final filter only allows paths which have the same number of edges as those in the "counter" variable.

这篇关于使用 ArangoDb AQL 过滤不同的图边类型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆