amigoz
amigoz

Reputation: 3

can we relate a property with other property of same vertex

A sample vertex

g.addV('a').property('vehicle','v1').property('time',1000).property(list,'vehicle','v2').property(list,'time',830)

how can we map the values in property 'vehicle' to the values in property 'time'. I tired the following code

g.V(1).hasKey('vehicle').map(hasKey('time'))

To find path I tired following code

g.V().hasLabel('a').repeat(out().simplePath()).until(hasLabel('h')).path().by(union(label(),values('vehicle','time')).fold())

can you help me please

Upvotes: 0

Views: 171

Answers (2)

Kelvin Lawrence
Kelvin Lawrence

Reputation: 14391

Changing the data model makes these kinds of queries easier to write. If you use vertices and edges to model the vehicles and times instead of lists stored as properties then you can do something like this.

g.addV('A').as('a').
  addV('B').as('b').
  addV('C').as('c').
  addV('vehicle').as('v1').property('time',10).property('name','V1').
  addV('vehicle').as('v2').property('time',8).property('name','V2').
  addV('vehicle').as('v3').property('time',5).property('name','V3').
  addV('vehicle').as('v4').property('time',6).property('name','V4').
  addV('vehicle').as('v5').property('time',5).property('name','V5').
  addV('vehicle').as('v6').property('time',6).property('name','V6').
  addE('route').from('a').to('b').
  addE('route').from('b').to('c').
  addE('vehicle_info').from('a').to('v1').
  addE('vehicle_info').from('a').to('v2').
  addE('vehicle_info').from('b').to('v3').
  addE('vehicle_info').from('b').to('v4').
  addE('vehicle_info').from('c').to('v5').
  addE('vehicle_info').from('c').to('v6').
  iterate()

gremlin> g.V().hasLabel('A').
......1>   repeat(out('route').simplePath()).
......2>     until(hasLabel('C')).
......3>   path().
......4>     by(union(label(),out('vehicle_info').values('name','time').fold()).fold())

==>[[A,[V1,10,V2,8]],[B,[V3,5,V4,6]],[C,[V5,5,V6,6]]]  

EDITED to add:

You can filter by the time as follows:

gremlin> g.V().hasLabel('A').
......1>   repeat(out('route').simplePath()).
......2>     until(hasLabel('C')).
......3>   path().
......4>     by(union(label(),out('vehicle_info').has('time',between(5,10)).values('name','time').fold())
.fold()) 
==>[[A,[V2,8]],[B,[V3,5,V4,6]],[C,[V5,5,V6,6]]]  

Upvotes: 0

bechbd
bechbd

Reputation: 6341

This can be accomplished like this:

g.V(18).property('time', __.values('vehicle'))

Which will map the list property like this:

gremlin> g.addV('a').property('vehicle','v1').property('time',1000).property(list,'vehicle','v2').property(list,'time',830)
==>v[18]
gremlin> g.V(18).valueMap()
==>[time:[1000,830],vehicle:[v1,v2]]
gremlin> g.V(18).property(list, 'time', __.values('vehicle'))
==>v[18]
gremlin> g.V(18).valueMap()
==>[time:[v1,v1],vehicle:[v1,v2]]

Upvotes: 0

Related Questions