Gremlin 小叮当:小精灵重访被访问的边缘
样本数据: 查询以创建样本数据Gremlin 小叮当:小精灵重访被访问的边缘,gremlin,tinkerpop3,gremlin-server,Gremlin,Tinkerpop3,Gremlin Server,样本数据: 查询以创建样本数据 g.addV("Test1").property("title", "A") g.addV("Test2").property("title", "B") g.addV("Test3").property("title", "C") g.addV("Test4").property("title", "D") g.V().has("Test1", "title", "A").addE("rel").to(g.V().has("Test2", "title",
g.addV("Test1").property("title", "A")
g.addV("Test2").property("title", "B")
g.addV("Test3").property("title", "C")
g.addV("Test4").property("title", "D")
g.V().has("Test1", "title", "A").addE("rel").to(g.V().has("Test2", "title", "B"))
g.V().has("Test2", "title", "B").addE("rel").to(g.V().has("Test3", "title", "C"))
g.V().has("Test3", "title", "C").addE("rel").to(g.V().has("Test4", "title", "D"))
查询:
A
如何连接到A
g.V().has("Test1", "title", "A").as("nodes")
.repeat(both().as("nodes"))
.emit(hasLabel("Test1")).hasLabel("Test1")
.limit(25)
.project("val").by(select(all, "nodes").unfold().values("title").fold())
结果(限值25
)
好的,让我们试试重复数据消除
g.V().has("Test1", "title", "A").as("nodes")
.repeat(both().as("nodes").dedup())
.emit(hasLabel("Test1")).hasLabel("Test1")
.project("val").by(select(all, "nodes").unfold().values("title").fold())
结果
{'val': ['A', 'B', 'A']}
A
和B
之间正好有一条边。那么为什么小精灵会在同一条边上穿越呢?我写错查询了吗
Cypher查询的行为方式似乎是正确的
MATCH p=((n:Test1)-[*]-(m:Test1)) RETURN p
Gremlin服务器版本:3.3.1看起来您只需要非循环路径:
g.V().has("Test1", "title", "A").
repeat(both().simplePath()).
until(hasLabel("Test1")).
path().
by("title")
看起来您只需要非循环路径:
g.V().has("Test1", "title", "A").
repeat(both().simplePath()).
until(hasLabel("Test1")).
path().
by("title")
我觉得重复数据消除对我来说正是如此。尝试并理解了
dedup
和simplePath
differencededup对于当前步骤是全局的,simplePath对于当前路径是局部的。我觉得dedup
对我来说正是如此。必须尝试并理解重复数据消除
和simplePath
差异对于当前步骤,重复数据消除是全局的,对于当前路径,simplePath是本地的。