我们在下面有下面的图表数据。只有5个顶点,但我们有很多边。我如何处理以下Querys?我想从一个节点到另一个节点的路径。或者我只想获得循环路径。
suresh = graph.addVertex(label,'person','uuid','7bff1bc0-cef1-1033-8f28-d99da6cfd8a9')
robin_niu = graph.addVertex(label,'person','uuid','e3348740-d37f-1031-8b5b-89fbb6fdad64')
hujunjie = graph.addVertex(label,'person','uuid','5e5139c0-dbe7-102e-8780-bedba724cbf7')
clintpollitt = graph.addVertex(label,'person','uuid','d92c6340-f98b-1035-85d7-bee5d5cc5ebe')
yanjuqi = graph.addVertex(label,'person','uuid','2d9fba40-74c7-1033-8e84-d3a6c90ad2e9')
suresh.addEdge('Communication',robin_niu,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',robin_niu,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',robin_niu,'date','2017-11-03T00:00:00Z','weight',1)
suresh.addEdge('Communication',robin_niu,'date','2017-11-04T00:00:00Z','weight',1)
suresh.addEdge('Communication',robin_niu,'date','2017-11-05T00:00:00Z','weight',1)
suresh.addEdge('Communication',hujunjie,'date','2017-12-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',hujunjie,'date','2017-12-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',hujunjie,'date','2017-12-03T00:00:00Z','weight',1)
suresh.addEdge('Communication',hujunjie,'date','2017-12-04T00:00:00Z','weight',1)
suresh.addEdge('Communication',hujunjie,'date','2017-12-05T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-10-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-10-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-10-03T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-10-04T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-10-05T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-01-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-01-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-01-03T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-01-04T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-01-05T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-11-03T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-11-04T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-11-05T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-12-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-12-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-12-03T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-12-04T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-12-05T00:00:00Z','weight',1)
suresh.addEdge('Communication',yanjuqi,'date','2017-12-05T00:00:00Z','weight',1)
suresh.addEdge('ProfilesReportingToChain',clintpollitt,'date','2016-12-01T00:00:00Z','weight',5)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-01T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-02T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
suresh.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',robin_niu,'date','2017-12-01T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',robin_niu,'date','2017-12-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',robin_niu,'date','2017-12-03T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',hujunjie,'date','2017-11-01T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',hujunjie,'date','2017-12-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',hujunjie,'date','2017-10-03T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',hujunjie,'date','2017-12-04T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',hujunjie,'date','2017-12-05T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-10-01T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-10-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-10-03T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-10-04T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-10-05T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-01-01T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-01-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-01-03T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-01-04T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-01-05T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-11-01T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-11-03T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-11-04T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',yanjuqi,'date','2017-11-05T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-01T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-01T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-01T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-01T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-01T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-02T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-11T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-11T00:00:00Z','weight',1)
clintpollitt.addEdge('Communication',suresh,'date','2017-11-11T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',robin_niu,'date','2017-12-11T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',robin_niu,'date','2017-12-12T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',robin_niu,'date','2017-12-13T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',hujunjie,'date','2017-11-11T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',hujunjie,'date','2017-12-12T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',hujunjie,'date','2017-10-13T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',hujunjie,'date','2017-12-14T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',hujunjie,'date','2017-12-15T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',clintpollitt,'date','2017-10-01T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',clintpollitt,'date','2017-10-02T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',clintpollitt,'date','2017-10-03T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',clintpollitt,'date','2017-10-04T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',suresh,'date','2017-10-05T00:00:00Z','weight',1)
yanjuqi.addEdge('Communication',suresh,'date','2017-01-01T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',hujunjie,'date','2017-12-11T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',hujunjie,'date','2017-12-12T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',hujunjie,'date','2017-12-13T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',hujunjie,'date','2017-11-11T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',hujunjie,'date','2017-12-12T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',hujunjie,'date','2017-10-13T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',yanjuqi,'date','2017-12-14T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',yanjuqi,'date','2017-12-15T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',clintpollitt,'date','2017-10-01T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',suresh,'date','2017-11-01T00:00:00Z','weight',1)
robin_niu.addEdge('Communication',suresh,'date','2017-01-01T00:00:00Z','weight',1)
robin_niu.addEdge('ProfilesReportingToChain',yanjuqi,'date','2017-10-02T00:00:00Z','weight',5)
robin_niu.addEdge('ProfilesColleague',hujunjie,'date','2017-10-03T00:00:00Z','weight',2)
hujunjie.addEdge('Communication',robin_niu,'date','2017-12-11T00:00:00Z','weight',1)
hujunjie.addEdge('Communication',robin_niu,'date','2017-12-12T00:00:00Z','weight',1)
hujunjie.addEdge('Communication',clintpollitt,'date','2017-12-13T00:00:00Z','weight',1)
hujunjie.addEdge('Communication',clintpollitt,'date','2017-11-11T00:00:00Z','weight',1)
hujunjie.addEdge('Communication',clintpollitt,'date','2017-12-12T00:00:00Z','weight',1)
hujunjie.addEdge('Communication',suresh,'date','2017-10-13T00:00:00Z','weight',1)
hujunjie.addEdge('Communication',suresh,'date','2017-11-01T00:00:00Z','weight',1)
hujunjie.addEdge('Communication',suresh,'date','2017-01-01T00:00:00Z','weight',1)
hujunjie.addEdge('Communication',yanjuqi,'date','2017-12-14T00:00:00Z','weight',1)
hujunjie.addEdge('Communication',yanjuqi,'date','2017-12-15T00:00:00Z','weight',1)
hujunjie.addEdge('Communication',yanjuqi,'date','2017-10-01T00:00:00Z','weight',1)
hujunjie.addEdge('ProfilesReportingToChain',yanjuqi,'date','2016-10-02T00:00:00Z','weight',5)
hujunjie.addEdge('ProfilesColleague',robin_niu,'date','2017-10-03T00:00:00Z','weight',2)
我想从一个节点到另一个节点获取路径。
以下2个查询无法正常运行。我该如何解决这个问题?
g.V().has('uuid','e3348740-d37f-1031-8b5b-89fbb6fdad64').repeat(out()).until(has('uuid','2d9fba40-74c7-1033-8e84-d3a6c90ad2e9')).simplePath().path()
g.V().has('uuid','e3348740-d37f-1031-8b5b-89fbb6fdad64').as('v').
repeat(outE().as('e').inV().as('v')).
until(has('uuid','2d9fba40-74c7-1033-8e84-d3a6c90ad2e9')).
store('a').
by('uuid').
store('a').
by(select(all, 'v').unfold().values('uuid').fold()).
store('a').
by(select(all, 'e').unfold().
store('x').
by(union(values('weight'),
select('x').count(local)).fold()).
cap('x').
store('a').
by(unfold().limit(local, 1).fold()).unfold().
sack(assign).
by(constant(1d)).
sack(div).
by(union(constant(1d),
tail(local, 1)).sum()).
sack(mult).
by(limit(local, 1)).
sack().sum()).
cap('a')
答案 0 :(得分:2)
我不完全理解你的问题,但我读到它意味着你想找到这些顶点之间的独特路径,你可以得到:
gremlin> g.V().has('uuid','e3348740-d37f-1031-8b5b-89fbb6fdad64').
......1> repeat(out().simplePath()).
......2> until(has('uuid','2d9fba40-74c7-1033-8e84-d3a6c90ad2e9')).
......3> path().
......4> dedup()
==>[v[2],v[8]]
==>[v[2],v[4],v[8]]
==>[v[2],v[6],v[8]]
==>[v[2],v[0],v[8]]
==>[v[2],v[4],v[6],v[8]]
==>[v[2],v[4],v[0],v[8]]
==>[v[2],v[6],v[0],v[8]]
==>[v[2],v[6],v[4],v[8]]
==>[v[2],v[0],v[6],v[8]]
==>[v[2],v[0],v[4],v[8]]
==>[v[2],v[4],v[6],v[0],v[8]]
==>[v[2],v[4],v[0],v[6],v[8]]
==>[v[2],v[6],v[0],v[4],v[8]]
==>[v[2],v[6],v[4],v[0],v[8]]
==>[v[2],v[0],v[6],v[4],v[8]]
==>[v[2],v[0],v[4],v[6],v[8]]
当然,考虑到图表的结构,你必须遍历大量的路径才能实现:
gremlin> g.V().has('uuid','e3348740-d37f-1031-8b5b-89fbb6fdad64').
......1> repeat(out().simplePath()).
......2> until(has('uuid','2d9fba40-74c7-1033-8e84-d3a6c90ad2e9')).
......3> path().
......4> count()
==>34794
我进一步假设这是样本数据,并且您的实际数据可能有更多的路径需要评估。在考虑性能影响时,您需要密切关注此数字以及在此最佳情况下可能会遇到的边缘总数。请注意,索引对初始顶点查找之外的遍历没有帮助,但是,如果要以某种方式进一步过滤路径以减少从数据库返回的边数,则以顶点为中心的索引在这里可能会非常有用(例如"在2017-11-02T00:00:00Z'")找到我的所有路径。