Use statement from choose and option that check only if a value has been yielded
Hey everyone,
.choose(
.out(EDGE_TOUCHPOINT_ACTION_ITEM)
.hasLabel(VERTEX_LABEL_ACTION_ITEM)
.hasLabel(this.SHOPIFY)
.has(VERTEX_PROPERTY_ACTION, 'storeWide')
.has(VERTEX_PROPERTY_ACTIVE, true),
)
.option(.hasNext(), __.as('actionItemStoreWide'))
I'm trying to use choose + option to just figure out if the traversal in the choose step yields a value. If it does then create create an alias for it.
I know what I currently have won't work, but I added for some extra context.
Thanks in advance!
Solution:Jump to solution
i'm not sure i fully understand, but perhaps that's not relevant and i should just try to answer the question.
19 Replies
what do you need it to do if it doesn't yield a value?
nothing
just continue from before the choose statement
hmm - could you help me better understand the use case? what does a "conditional label" help you do?
basically if this node exists save it as an alias. if it doesn't move on
right, i understand what you want it to do, but i was more asking what you would use that for. it's not a use case i think i've ever come across so i was curious what you wanted to accomplish with that functionality. in knowing that answer we might even be able to provide a better way to accomplish your goal.
So i'm injecting an array of IDs after. Then I search weather Nodes with these IDs exist and have an edge with the first conditional node. If the conditional node doesn't exist we disregard those IDs.
Solution
i'm not sure i fully understand, but perhaps that's not relevant and i should just try to answer the question.
seems like you could just do this, right?
choose()
is basically if-then so the above says "if there are not out edges, then add the step label of 'found'"and if the choose yields to false, would I reach a compilation error?
or more correctly doesn't yield anything
there won't be a compilation error
that's valid Gremlin
or a runtime error sorry
ok
so if i call select on a non-existent alias that's fine?
i purposely chose
outE()
on the modern graph because there are three vertices without out edges
the query executes without any problems for those that evaluate to false there as you can see above
if you call select()
on something that doesn't exist, then newer versions of TinkerPop should have no problemok
let me try to back test on 3.4.x
thank you
I'm using the latest grelin version allowed by neptune
works fine on 3.4.x for what that's worth. neptune i think should be ok as well
i still don't quite see the point of this label though. if you dont use the unfound paths (and they get filtered on
select()
anyway), then is there a reason to not just prefer using a filter?maybe i left an important piece out. If the conditional vertex exists, but there is no vertex found, then we need to create it.
if the conditional vertex doesn't exist, we disregard all together.
if the conditional vertex exists and a vertex with the id is found, then we proceed onwards
essentially what we care about is this;
if the conditional vertex exists we need to upsert vertices with IDs from the array
if conditional vertex doesn't exist we may disregard the array of IDs entirely
i'm still feeling as though
choose()
is necessary here (and by extension the conditional step label). you may wish to share the entirety of your query now that you have a working example for that approach.sure things i will send it later