AT

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

Ddanielcraig2310/16/2023
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
Solution
Kkelvinl281610/17/2023
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]
Ddanielcraig2310/17/2023
Thanks Kelvin, is .store('a') equivalent to .aggregate(local, 'a')? I'd like to avoid deprecated traversal steps
Kkelvinl281610/17/2023
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...)
Ddanielcraig2310/17/2023
I agree

Looking for more? Join the community!

Want results from more Discord servers?
Add your server
Recommended Posts
Can GraphBinary be used to save a graph to file?Can GraphBinary be used to save graph in a file. Any example is welcome.How to get cardinality of property?I have a multi property and I want to find out its cardinality. How can I do that? valueMap/elementMinverted regex searchHey, In my vertices I store escaped regexp statements as labels (e.g: 'wh.' which in theory should Debug message spam from tinkerpop server 3.7Right now, when connecting to my local tinkerpop server, I am getting incredible amounts of debug loShould by() Modulator Work For More Types?This works. `gremlin> g.V().out().out().path().by("name") ==>[marko,josh,ripple] ==>[marko,josh,lop]InProcess GraphDB with Gremlin Support? (C# or NodeJS)Hello, is there any in process GraphDB out there in the world? Best would be c# or NodeJS and not JaEasiest Way to Get List Cardinality Properties As a List?What is the easiest way to retrieve the vertex properties that have list cardinality back as a list filter lambda in remote consolehi all, i’m trying to do filter on remote console to neptune server but keep getting MalformedQueryEwithin() and case insensitiveI need to check if a property of a node is in a list of values. How can I do that in a case insensitproject("p").by(__.values("a", "b") Only Outputs Single Property, Bug or Expected?I am curious why this does not behave in the way I expected. Not a problem - solution question. I Use of by()Can somebody explain the usecase of by() function in gremlin in very simple language.@GremlinDSL support in the GremlinLangScriptEngineHi, I recently sent a pull-request into the github ArcadeDB repository to add support binding custoRepeatStep does not appear to respect barriersI was digging into some traversal performance and had something similar to the following: ``` g.V(<Trying to find a Vertex using a variable injected earlier in the traversalI am trying to add a series of vertices and edges to an existing graph. The newly created Vertex wi