Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Select distinct nodes with Gremlin?

Tags:

gremlin

If there are multiple edges connecting the same pair of nodes, both will come back with duplicated nodes:

gremlin> v2 = g.addVertex(null,['x':5,'y':7])
==>v[360004]
gremlin> v3 = g.addVertex(null, ['x':2,'y':3])
==>v[360008]
gremlin> g.addEdge(v2,v3,'test')
==>e[6IeZ-1vEw-2F0LaTPQQu][360004-test->360008]
gremlin> g.addEdge(v2,v3,'test 2')
==>e[6If7-1vEw-2F0LaTPQQC][360004-test 2->360008]
gremlin> v2.both.map
==>{y=3, x=2}
==>{y=3, x=2}

How can ensure that I get back a distinct list of nodes?

like image 686
bcm360 Avatar asked Oct 24 '25 18:10

bcm360


1 Answers

dedup makes this easy and is explained in the Gremlin docs. For the example above:

gremlin> v2.both.dedup.map
==>{y=3, x=2}
like image 155
bcm360 Avatar answered Oct 28 '25 06:10

bcm360



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!