【发布时间】:2017-07-20 03:52:53
【问题描述】:
我正在 AQL (arangodb 3.1.22) 中编写图形遍历查询,其中对于返回的某些路径,我在路径对象中得到一个顶点,该顶点未连接到路径对象中返回的任何边(即边的_from/_to 属性与顶点_id 不匹配)。
我的工作假设路径对象只返回该路径上的顶点和边。这是一个错误的假设吗?
【问题讨论】:
-
你的假设是正确的,路径应该只包含路径上的顶点和边。您可以发布您的查询吗?
我正在 AQL (arangodb 3.1.22) 中编写图形遍历查询,其中对于返回的某些路径,我在路径对象中得到一个顶点,该顶点未连接到路径对象中返回的任何边(即边的_from/_to 属性与顶点_id 不匹配)。
我的工作假设路径对象只返回该路径上的顶点和边。这是一个错误的假设吗?
【问题讨论】:
如果将起点作为字符串传递,则遍历时根本不需要存在顶点:
FOR v, e IN 1..10 OUTBOUND "nodes/non-existing-start" edges
RETURN { vertex: v, _from: e._from, _to: e._to }
数据(集合nodes 中的顶点和edges 中的边):
non-existing-start
|
v
non-existing-1
|
v
non-existing-2
|
v
non-existing-3
它所做的是使用边缘索引沿着确实存在的边缘(_from 和_to 属性)遍历。集合nodes 必须存在,但未测试_from 和_to 中引用的顶点是否确实存在于该集合中。查询结果为:
[
{
"vertex": null,
"_from": "nodes/non-existing-start",
"_to": "nodes/non-existing-1"
},
{
"vertex": null,
"_from": "nodes/non-existing-1",
"_to": "nodes/non-existing-2"
},
{
"vertex": null,
"_from": "nodes/non-existing-2",
"_to": "nodes/non-existing-3"
}
]
如您所见,顶点是null,因此它们不存在。
您可以在删除顶点时使用托管图和general-graph 模块以及delete edges connected to a vertex 以确保一致性。
【讨论】: