Can I name the result of an anonymous traversal without moving the traverser?

I can currently do the following:
Graph graph = TinkerFactory.createModern();

GraphTraversalSource gts = AnonymousTraversalSource.traversal().withEmbedded(graph);

gts.V().hasLabel("person")
.has("name", "josh")
.where(__.out().has("name", "ripple"))
.project("rippleCreatorName", "rippleName", "rippleLang")
.by("name")
.by(__.out().has("name", "ripple").values("name"))
.by(__.out().has("name", "ripple").values("lang"))
.toList();
Graph graph = TinkerFactory.createModern();

GraphTraversalSource gts = AnonymousTraversalSource.traversal().withEmbedded(graph);

gts.V().hasLabel("person")
.has("name", "josh")
.where(__.out().has("name", "ripple"))
.project("rippleCreatorName", "rippleName", "rippleLang")
.by("name")
.by(__.out().has("name", "ripple").values("name"))
.by(__.out().has("name", "ripple").values("lang"))
.toList();
I wish I could do something like this instead:
Graph graph = TinkerFactory.createModern();

GraphTraversalSource gts = AnonymousTraversalSource.traversal().withEmbedded(graph);

gts.V().hasLabel("person").has("name", "josh")
.let("ripple", __.out().has("name", "ripple"))
.project("rippleCreatorName", "rippleName", "rippleLang")
.by("name")
.by(__.select("ripple").values("name"))
.by(__.select("ripple").values("lang"))
.toList()
Graph graph = TinkerFactory.createModern();

GraphTraversalSource gts = AnonymousTraversalSource.traversal().withEmbedded(graph);

gts.V().hasLabel("person").has("name", "josh")
.let("ripple", __.out().has("name", "ripple"))
.project("rippleCreatorName", "rippleName", "rippleLang")
.by("name")
.by(__.select("ripple").values("name"))
.by(__.select("ripple").values("lang"))
.toList()
What would you recommend to me? I only want to do __.out().has("name", "ripple") once, because in my project this filter is much longer so there is considerable repeated code.
Solution:
You could perhaps play around with store ``` gremlin> g.V().hasLabel("person"). ......1> has("name", "josh"). ......2> where(__.out().has("name", "ripple").store('a'))....
Jump to solution
4 Replies
Solution
kelvinl2816
kelvinl281614mo ago
You could perhaps play around with store
gremlin> g.V().hasLabel("person").
......1> has("name", "josh").
......2> where(__.out().has("name", "ripple").store('a')).
......3> project("rippleCreatorName", "rippleName", "rippleLang").
......4> by("name").
......5> by(select('a').unfold().values("name")).
......6> by(select('a').unfold().values("lang"))

==>[rippleCreatorName:josh,rippleName:ripple,rippleLang:java]
gremlin> g.V().hasLabel("person").
......1> has("name", "josh").
......2> where(__.out().has("name", "ripple").store('a')).
......3> project("rippleCreatorName", "rippleName", "rippleLang").
......4> by("name").
......5> by(select('a').unfold().values("name")).
......6> by(select('a').unfold().values("lang"))

==>[rippleCreatorName:josh,rippleName:ripple,rippleLang:java]
danielcraig23
danielcraig23OP14mo ago
Thanks Kelvin, is .store('a') equivalent to .aggregate(local, 'a')? I'd like to avoid deprecated traversal steps
kelvinl2816
kelvinl281614mo ago
It is but I'm arguing we should never remove store and likewise reverse its deprecated status. I think store is more discoverable than (aggregate,local...)
danielcraig23
danielcraig23OP14mo ago
I agree
Want results from more Discord servers?
Add your server