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:
i'm not sure i fully understand, but perhaps that's not relevant and i should just try to answer the question.
Jump to solution
19 Replies
spmallette
spmallette2y ago
what do you need it to do if it doesn't yield a value?
kyano_k
kyano_kOP2y ago
nothing just continue from before the choose statement
spmallette
spmallette2y ago
hmm - could you help me better understand the use case? what does a "conditional label" help you do?
kyano_k
kyano_kOP2y ago
basically if this node exists save it as an alias. if it doesn't move on
spmallette
spmallette2y ago
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.
kyano_k
kyano_kOP2y ago
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
spmallette
spmallette2y ago
i'm not sure i fully understand, but perhaps that's not relevant and i should just try to answer the question.
spmallette
spmallette2y ago
seems like you could just do this, right?
gremlin> g.V().as('x').choose(outE(), __.as('found')).select('x','found')
==>[x:v[1],found:v[1]]
==>[x:v[4],found:v[4]]
==>[x:v[6],found:v[6]]
gremlin> g.V().as('x').choose(outE(), __.as('found')).select('x','found')
==>[x:v[1],found:v[1]]
==>[x:v[4],found:v[4]]
==>[x:v[6],found:v[6]]
choose() is basically if-then so the above says "if there are not out edges, then add the step label of 'found'"
kyano_k
kyano_kOP2y ago
and if the choose yields to false, would I reach a compilation error? or more correctly doesn't yield anything
spmallette
spmallette2y ago
there won't be a compilation error that's valid Gremlin
kyano_k
kyano_kOP2y ago
or a runtime error sorry ok so if i call select on a non-existent alias that's fine?
spmallette
spmallette2y ago
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 problem
kyano_k
kyano_kOP2y ago
ok
spmallette
spmallette2y ago
let me try to back test on 3.4.x
kyano_k
kyano_kOP2y ago
thank you I'm using the latest grelin version allowed by neptune
spmallette
spmallette2y ago
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?
kyano_k
kyano_kOP2y ago
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
spmallette
spmallette2y ago
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.
kyano_k
kyano_kOP2y ago
sure things i will send it later
Want results from more Discord servers?
Add your server