格林姆林。在 parent-child 关系中,按 child 的较高版本过滤

Gremlin. In a parent-child relation, filter by the higher version of the child

我有一个 parent-child 结构。 child 有一个版本和一个组。我需要按 groupparent.

为最新版本分组创建过滤器

此查询 returns 值正确,但我需要每种情况的顶点:

g.V().hasLabel('Child')
.group()
.by(
  __.group()
  .by('tenant')
  .by(__.in('Has').values('name'))
)
.by(__.values('version').max())

有什么提示或建议吗?

感谢您的帮助!


数据:

g.addV('Parent').property('name','child1').as('re1').addV('Parent').property('name','child2').as('re2').addV('Parent').property('name','child3').as('re3').addV('Child').property('tenant','group1').property('version','0.0.1').as('dp1').addE('Has').from('re1').to('dp1').addV('Child').property('tenant','group1').property('version','0.0.2').as('dp4').addE('Has').from('re1').to('dp4').addV('Child').property('tenant','group2').property('version','0.1.2').as('dp5').addE('Has').from('re1').to('dp5').addV('Child').property('tenant','group1').property('version','0.1.2').as('dp2').addE('Has').from('re2').to('dp2').addV('Child').property('tenant','group1').property('version','3.0.3').as('dp3').addE('Has').from('re3').to('dp3')

输出:

{{group1=child1}=0.0.2, {group2=child1}=0.1.2, {group1=child3}=3.0.3, {group1=child2}=0.1.2}

but I need the vertex for each case

我假设您指的是 Child 顶点。下面的遍历就可以得到所有的数据:

gremlin> g.V().hasLabel("Child").
           group().
             by(union(values("tenant"), __.in("Has").values("name")).fold()).
           unfold()
==>[group2, child1]=[v[14]]
==>[group1, child1]=[v[6], v[10]]
==>[group1, child2]=[v[18]]
==>[group1, child3]=[v[22]]

但是,您可能希望它的结构稍微好一点:

gremlin> g.V().hasLabel("Child").
           group().
             by(union(values("tenant"), __.in("Has").values("name")).fold()).
           unfold().
           project('tenant','name','v').
             by(select(keys).limit(local, 1)).
             by(select(keys).tail(local, 1)).
             by(select(values).unfold())
==>[tenant:group2,name:child1,v:v[14]]
==>[tenant:group1,name:child1,v:v[6]]
==>[tenant:group1,name:child2,v:v[18]]
==>[tenant:group1,name:child3,v:v[22]]