我正在创建2个用户(uid = 1和uid = 2),每个都有2个版本。
g.addV('user1').property('uid',1).property('version',1)
.addV('user1').property('uid',1).property('version',2)
.addV('user1').property('uid',2).property('version',1)
.addV('user1').property('uid',2).property('version',2)
我想从每个uid获取最新版本,我使用键uid
作为groupBy
键并获取最新的信息,如图所示
g.V().hasLabel('user1')
.group().by('uid').by(fold().order(Scope.local).by('version', Order.desc).unfold().limit(1)) //GraphTraversal<Vertex,Map<Object, Object>>
.flatmap(t -> t.get().values().iterator()) // convert to GraphTraversal<Vertex, Vertex>
//traverse out and get the path
.out('friend').path().by(elementMap())
感谢任何帮助!
该group
步骤有两种模式。没有标签,它起到屏障作用,而带有标签,则起到副作用。您可以按以下方式使用数据使结果流经一个组。
gremlin> g.V().group('x').by('uid').by(values('version').max())
==>v[42306]
==>v[42309]
==>v[42312]
==>v[42315]
==>v[42318]
gremlin> g.V().group('x').by('uid').by(values('version').max()).cap('x')
==>[1:2,2:2]
您当然可以添加更多遍历步骤,然后再决定要对该组执行的操作。如:
g.V().group('x').by('uid').by(values('version').max())out()...
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句