hey guys ,how to query a person relational depth


李平 <lipin...@...>
 

I want to know ,one person in the janusGraph ,his relational depth,use gremlin


Jason Plurad <plu...@...>
 

There's a recipe for this http://tinkerpop.apache.org/docs/current/recipes/#_maximum_depth


On Wednesday, August 23, 2017 at 3:52:14 AM UTC-4, 李平 wrote:
I want to know ,one person in the janusGraph ,his relational depth,use gremlin


李平 <lipin...@...>
 

gremlin> g.addV().property('name', 'A').as('a'). addV().property('phone', '110').as('b'). addV().property('name', 'C').as('c'). addV().property('phone', '111').as('d'). addV().property('name', 'E').as('e'). addV().property('phone', '112').as('f'). addV().property('name', 'G').as('g'). addE('hasPhone').from('a').to('b'). addE('hasPhone').from('c').to('d'). addE('hasPhone').from('c').to('b'). addE('hasPhone').from('e').to('d').
addE('hasPhone').from('e').to('f'). addE('hasPhone').from('g').to('b').iterate()



if I want to know vertex A's relation depth how to write the gremlin commond,   

I  write like this 

g.V().has('userId','1').repeat(__.as("a").out().in().where(neq("a"))).emit().path().count(local).max()



but it seem endless loop,
在 2017年8月23日星期三 UTC+8下午9:16:21,Jason Plurad写道:

There's a recipe for this http://tinkerpop.apache.org/docs/current/recipes/#_maximum_depth

On Wednesday, August 23, 2017 at 3:52:14 AM UTC-4, 李平 wrote:
I want to know ,one person in the janusGraph ,his relational depth,use gremlin


Jason Plurad <plu...@...>
 

Use simplePath() to avoid cycles http://tinkerpop.apache.org/docs/current/reference/#simplepath-step

gremlin> graph = JanusGraphFactory.open('inmemory'); g = graph.traversal()
==>graphtraversalsource[standardjanusgraph[inmemory:[127.0.0.1]], standard]
gremlin
> g.addV().property('name', 'A').as('a').
......1>            addV().property('phone', '110').as('b').
......2>            addV().property('name', 'C').as('c').
......3>            addV().property('phone', '111').as('d').
......4>            addV().property('name', 'E').as('e').
......5>            addV().property('phone', '112').as('f').
......6>            addV().property('name', 'G').as('g').
......7>            addE('hasPhone').from('a').to('b').
......8>            addE('hasPhone').from('c').to('d').
......9>            addE('hasPhone').from('c').to('b').
.....10>            addE('hasPhone').from('e').to('d').
.....11>            addE('hasPhone').from('e').to('f').
.....12>            addE('hasPhone').from('g').to('b').iterate()
gremlin
> g.V().has('name', 'A').repeat(both().simplePath()).emit().path().count(local).max()
11:11:58 WARN  org.janusgraph.graphdb.transaction.StandardJanusGraphTx  - Query requires iterating over all vertices [(name = A)]. For better performance, use indexes
==>6



On Wednesday, August 23, 2017 at 10:26:12 PM UTC-4, 李平 wrote:
gremlin> g.addV().property('name', 'A').as('a'). addV().property('phone', '110').as('b'). addV().property('name', 'C').as('c'). addV().property('phone', '111').as('d'). addV().property('name', 'E').as('e'). addV().property('phone', '112').as('f'). addV().property('name', 'G').as('g'). addE('hasPhone').from('a').to('b'). addE('hasPhone').from('c').to('d'). addE('hasPhone').from('c').to('b'). addE('hasPhone').from('e').to('d').
addE('hasPhone').from('e').to('f'). addE('hasPhone').from('g').to('b').iterate()



if I want to know vertex A's relation depth how to write the gremlin commond,   

I  write like this 

g.V().has('userId','1').repeat(__.as("a").out().in().where(neq("a"))).emit().path().count(local).max()



but it seem endless loop,
在 2017年8月23日星期三 UTC+8下午9:16:21,Jason Plurad写道:
There's a recipe for this http://tinkerpop.apache.org/docs/current/recipes/#_maximum_depth

On Wednesday, August 23, 2017 at 3:52:14 AM UTC-4, 李平 wrote:
I want to know ,one person in the janusGraph ,his relational depth,use gremlin


Daniel Kuppitz <me@...>
 

Any of the following 2 queries should do the trick:

gremlin> g.V().has('name','A').
           repeat(out('hasPhone').in('hasPhone').simplePath()).emit().
           project('name','depth').
             by('name').
             by(path().count(local))
==>[name:C,depth:3]
==>[name:G,depth:3]
==>[name:E,depth:5]

gremlin> g.V().has('name','A').
           repeat(out('hasPhone').in('hasPhone').simplePath().as('x')).emit().
           project('name','depth').
             by('name').
             by(select(all, 'x').count(local))
==>[name:C,depth:1]
==>[name:G,depth:1]
==>[name:E,depth:2]

Pretty much depends on how you define "relation depth".

Cheers,
Daniel




On Wed, Aug 23, 2017 at 7:26 PM, 李平 <lipin...@...> wrote:
gremlin> g.addV().property('name', 'A').as('a'). addV().property('phone', '110').as('b'). addV().property('name', 'C').as('c'). addV().property('phone', '111').as('d'). addV().property('name', 'E').as('e'). addV().property('phone', '112').as('f'). addV().property('name', 'G').as('g'). addE('hasPhone').from('a').to('b'). addE('hasPhone').from('c').to('d'). addE('hasPhone').from('c').to('b'). addE('hasPhone').from('e').to('d').
addE('hasPhone').from('e').to('f'). addE('hasPhone').from('g').to('b').iterate()



if I want to know vertex A's relation depth how to write the gremlin commond,   

I  write like this 

g.V().has('userId','1').repeat(__.as("a").out().in().where(neq("a"))).emit().path().count(local).max()



but it seem endless loop,
在 2017年8月23日星期三 UTC+8下午9:16:21,Jason Plurad写道:
There's a recipe for this http://tinkerpop.apache.org/docs/current/recipes/#_maximum_depth

On Wednesday, August 23, 2017 at 3:52:14 AM UTC-4, 李平 wrote:
I want to know ,one person in the janusGraph ,his relational depth,use gremlin

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-users+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


李平 <lipin...@...>
 

ok  thanks   ,another question , how to skip a super vertex ,this vertex has lots of edge ,for example .the phone is 911 or this phone is custom service,  so a lots of people has relation with this vertex , when I query a person two layer relation depth, it will query a lots of person
custom service;


在 2017年8月25日星期五 UTC+8上午2:32:17,Daniel Kuppitz写道:

Any of the following 2 queries should do the trick:

gremlin> g.V().has('name','A').
           repeat(out('hasPhone').in('hasPhone').simplePath()).emit().
           project('name','depth').
             by('name').
             by(path().count(local))
==>[name:C,depth:3]
==>[name:G,depth:3]
==>[name:E,depth:5]

gremlin> g.V().has('name','A').
           repeat(out('hasPhone').in('hasPhone').simplePath().as('x')).emit().
           project('name','depth').
             by('name').
             by(select(all, 'x').count(local))
==>[name:C,depth:1]
==>[name:G,depth:1]
==>[name:E,depth:2]

Pretty much depends on how you define "relation depth".

Cheers,
Daniel




On Wed, Aug 23, 2017 at 7:26 PM, 李平 <li...@...> wrote:
gremlin> g.addV().property('name', 'A').as('a'). addV().property('phone', '110').as('b'). addV().property('name', 'C').as('c'). addV().property('phone', '111').as('d'). addV().property('name', 'E').as('e'). addV().property('phone', '112').as('f'). addV().property('name', 'G').as('g'). addE('hasPhone').from('a').to('b'). addE('hasPhone').from('c').to('d'). addE('hasPhone').from('c').to('b'). addE('hasPhone').from('e').to('d').
addE('hasPhone').from('e').to('f'). addE('hasPhone').from('g').to('b').iterate()



if I want to know vertex A's relation depth how to write the gremlin commond,   

I  write like this 

g.V().has('userId','1').repeat(__.as("a").out().in().where(neq("a"))).emit().path().count(local).max()



but it seem endless loop,
在 2017年8月23日星期三 UTC+8下午9:16:21,Jason Plurad写道:
There's a recipe for this http://tinkerpop.apache.org/docs/current/recipes/#_maximum_depth

On Wednesday, August 23, 2017 at 3:52:14 AM UTC-4, 李平 wrote:
I want to know ,one person in the janusGraph ,his relational depth,use gremlin

--
You received this message because you are subscribed to the Google Groups "JanusGraph users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to janusgraph-use...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.