Reputation: 77234
I have a Gremlin vertex with set-valued properties emails
and phones
. As part of my update logic, I am trying to drop and recreate these properties:
String key = ThreadLocalRandom.current().nextInt()
def dropped = vtx.as(key).properties('emails', 'phones').drop().<Vertex>select(key)
My expectation is that the vertex will get tagged by as
, then I traverse to the properties and drop them, then use select
to return to the vertex for further processing. However, executing this always results in an empty traversal.
I have been able to get the traversal to return a result by instead saying
def dropped = vtx.sideEffect(__.properties('emails', 'phones').drop())
but I want to ensure that the properties are dropped strictly before continuing, as I then proceed to re-insert them.
Why does the original traversal not behave as I expect it? With the sideEffect
version, do I need to add a barrier()
for correctness, and if so, is that sufficient?
Upvotes: 1
Views: 522
Reputation: 46226
Note that drop()
is a filter step so it produces no traversers. Everything that goes into it is removed from the stream. In that way, your select()
is never called. You can see this with with profile()
:
gremlin> g.V().as('a').drop().select('a').profile()
==>Traversal Metrics
Step Count Traversers Time (ms) % Dur
=============================================================================================================
TinkerGraphStep(vertex,[])@[a] 808 808 1.922 19.04
DropStep 8.138 80.60
SelectOneStep(last,a) 0.010 0.10
NoOpBarrierStep(2500) 0.026 0.26
>TOTAL - - 10.097 -
Your approach with sideEffect()
is the correct way to do what you are trying to do. The side-effect traversal should be iterated to completion before proceeding so I would expect all properties removed when the sideEffect()
step completes for the traverser passing through it.
Upvotes: 2