返回以其他路径尚未结束的顶点为结尾的路径在Gremlin中应该如何处理?

huangapple go评论49阅读模式
英文:

How do I return in Gremlin only paths which ends with vertices that other paths didn't end with yet?

问题

假设我有以下图:

A->B, B->D
A->C, C->D
A->E

我想返回所有从A开始的路径,但不包括以相同顶点结尾的多条路径。因此,在这种情况下,结果将是:
A->B->D(或A->C->D)和A->E

由于图很大且可能有很多路径,如果引擎可以以高效的方式修剪路径而无需先收集所有路径,那将是可取的。

英文:

Let's assume I have the following graph:

A->B, B->D
A->C, C->D
A->E

I want to return all paths which start from A, but don't include multiple paths which end with the same vertex.
So in case, the result will be:
A->B->D (or A->C->D) and A->E

Since the graph is very big and there can be a lot of paths, if there is an efficient way the engine can prune the paths without collecting all of them first, it is preferable.

答案1

得分: 1

根据图中的数据循环程度,这可能是一个昂贵的查询。我假设每个最终目标都是叶节点。在这种情况下,基本查询可能会变成这样:

g.V('A').
  repeat(out().simplePath()).
  until(not(out())).
  where(without('x')).store('x').
  path()
英文:

Depending upon how cyclic the data in the graph is, this can be an expensive query. I am assuming each eventual target is a leaf node. In such cases, the basic query might end up something like this:

g.V('A').
  repeat(out().simplePath()).
  until(not(out())).
  where(without('x')).store('x').
  path()

huangapple
  • 本文由 发表于 2023年2月16日 05:04:43
  • 转载请务必保留本文链接:https://go.coder-hub.com/75465419.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定