Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/webpack/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Tinkerpop Gremlin按键分组并获取最新信息_Gremlin_Tinkerpop - Fatal编程技术网

Tinkerpop Gremlin按键分组并获取最新信息

Tinkerpop Gremlin按键分组并获取最新信息,gremlin,tinkerpop,Gremlin,Tinkerpop,我正在创建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('versi

我正在创建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())
g.V().hasLabel('user1')
.group().by('uid').by(fold().order(Scope.local).by('version',order.desc.).unfold().limit(1))//GraphTraversal
.flatmap(t->t.get().values().iterator())//转换为GraphTraversal
//横穿出去,找到那条路
.out('friend').path().by(elementMap())
  • 这一要求的最佳方法是什么
  • 小精灵更喜欢用什么方法将贴图转换为平面贴图内的顶点,而不是使用lambda?假设我想在此之后添加更多步骤

  • 谢谢你的帮助

    组步骤有两种模式。如果没有标签,它会起到屏障的作用,但如果有标签,它会起到副作用。您可以使用以下数据使结果在组中流动

    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()...
    

    你能分享一下你想得到的结果吗。你在找这样的东西吗?gremlin>g.V().group().by('uid').by(values('version').max())=>[1:2,2:2]@KelvinLawrence我想继续进一步遍历[g.V().group().by('uid').by(values('version').max())…out('friend').path().by(elementMap())]在这种情况下,您可以通过给组一个标签g.V().group('x').by('uid').by('values('version'))使组产生副作用.max()).out()。。。。然后,当你完成后,只需组装最终结果。是的,这就是我想要的。我假设第二组副作用也可以添加到out中,对吗?例如[g.V().group('x').by('uid').by(values('version').max()).out().group('x').by('uid').by(…).path()]。非常感谢。如果其他人有相同的问题,我将键入一个快速答案。我想将.out()应用于分组顶点[1:2,2:2]的结果,而不是所有顶点。这可能吗?