kishore k
kishore k

Reputation: 147

Titan graph: Finding vertices without outgoing edges

I have Parent vertex (P) connected to child vertices (C1, C2, C3,..Cn) (via an outgoing edge Label "dep") , Where Cn can be very huge. These child vertices (C1, C2,..) may or may not be connected to other vertices via an outgoing edge label "frnds". Is there a way in Gremlin to find out all Child vertices of (P) that does not have any out going edges with label "frnds" ?

Regards, Kumar

Upvotes: 2

Views: 891

Answers (2)

kusha
kusha

Reputation: 63

g.v('p').out('dep').filter{!it.outE('frnds').hasNext()}.range(0,100) query works even faster when u sepcify range. It will get 100 vertices with no outgoing edges

Upvotes: 0

Faber
Faber

Reputation: 1552

The toy graph:

g = new TinkerGraph()
p = g.addVertex('p')
c1 = g.addVertex('c1')
c2 = g.addVertex('c2')
c3 = g.addVertex('c3')
o1 = g.addVertex('o1')
o2 = g.addVertex('o2')
g.addEdge(p, c1, 'dep')
g.addEdge(p, c2, 'dep')
g.addEdge(p, c3, 'dep')
g.addEdge(c1, o1, 'frnds')
g.addEdge(c1, o2, 'frnds')
g.addEdge(c2, o2, 'frnds')

A solution for your query description (probably not the smartest):

r = []; g.v('p').out('dep').store(r).outE('frnds').outV.sideEffect{r.remove(it)}

output:

r
==>v[c3]

Update: Bit a shorter version, probably also bit more efficient:

g.v('p').out('dep').filter{!it.outE('frnds').hasNext()}
==>v[c3]

Upvotes: 3

Related Questions