Pass label to coalesce

When I want to pass a label to a coalesce step I get follwoing error:
"addE(occupied) failed because the from() traversal (which should give a Vertex) failed with: The provided traverser does not map to a value: v[10190][TinkerVertex]->[SelectOneStep(last,u,null)
"addE(occupied) failed because the from() traversal (which should give a Vertex) failed with: The provided traverser does not map to a value: v[10190][TinkerVertex]->[SelectOneStep(last,u,null)
this is my code:
g.addV('user').property('name', 'mari').as('u').
out().has('location','name', "Z").fold().
coalesce(
__.unfold(),
__.addV('location').property('name', "Z").as("loc").
addE('occupied').from('u').to('loc')
)
g.addV('user').property('name', 'mari').as('u').
out().has('location','name', "Z").fold().
coalesce(
__.unfold(),
__.addV('location').property('name', "Z").as("loc").
addE('occupied').from('u').to('loc')
)
Appreciate your help
2 Replies
spmallette
spmallette17mo ago
A fold() step is a type of reducing barrier step. Those steps destroy the path history along which Gremlin has travelled. Therefore "u" is no longer accessible. In most cases, it's relatively easy to work around this limitation by using a side-effect:
gremlin> g.addV('user').
......1> property('name', 'mari').store('u').
......2> out().
......3> has('location', 'name', "Z").
......4> fold().
......5> coalesce(
......6> __.unfold(),
......7> __.addV('location').
......8> property('name', "Z").
......9> addE('occupied').from(select('u').unfold()))
==>e[4][0-occupied->2]
gremlin> g.addV('user').
......1> property('name', 'mari').store('u').
......2> out().
......3> has('location', 'name', "Z").
......4> fold().
......5> coalesce(
......6> __.unfold(),
......7> __.addV('location').
......8> property('name', "Z").
......9> addE('occupied').from(select('u').unfold()))
==>e[4][0-occupied->2]
isohrab
isohrabOP17mo ago
@spmallette thank you so much for your help. I could solve my problem with the help of your answer.
Want results from more Discord servers?
Add your server