0

I have a parent-child structure. The child has a version and a group. I need to create a filter for the newest version grouping by group,parent.

This query returns the values properly, but I need the vertex for each case:

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

Any tips or suggestions?

Thanks for the help!


Data:

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')

output:

{{group1=child1}=0.0.2, {group2=child1}=0.1.2, {group1=child3}=3.0.3, {group1=child2}=0.1.2}
cmaluenda
  • 2,099
  • 1
  • 14
  • 15
  • Could you please show the output you get now and the output you would like to see. Also if you could provide a small test graph that would be very helpful. – Kelvin Lawrence Oct 08 '19 at 22:15
  • I updated my question with a data sample and the output. Thanks @KelvinLawrence – cmaluenda Oct 08 '19 at 22:28

1 Answers1

2

but I need the vertex for each case

I assume that you mean the Child vertex. The following traversal will give you all the data:

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]]

However, you probably want it to be in a slightly better structure:

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]]
Daniel Kuppitz
  • 10,846
  • 1
  • 25
  • 34