Using the modern graph, how can I write a query that finds the name of the oldest person?

I want to take the graph produced by TinkerFactory.createModern() and write a query that finds the oldest person and returns their name. I want to learn to use the max() traversal step.
4 Replies
spmallette
spmallette•12mo ago
I'm not sure I'd use max() in that case. It would be more like:
gremlin> g.V().order().by('age',desc).limit(1).valueMap()
==>[name:[peter],age:[35]]
gremlin> g.V().order().by('age',desc).limit(1).valueMap()
==>[name:[peter],age:[35]]
i guess you might have a case for max() if it was more a traversal like:
gremlin> g.V().values('age').max()
==>35
gremlin> g.V().values('age').max()
==>35
danielcraig23
danielcraig23•12mo ago
OK thank you!
kelvinl2816
kelvinl2816•12mo ago
For this specific case you would typically use an order...by approach. The tricky part with max is that it is a reducing barrier step, once you use it all traversers that had been exploring the graph are flattened into one. So in this specifc case you typically would not use max but would do something like
gremlin> g.V().has('age').order().by('age',desc).limit(1).valueMap()
==>[name:[peter],age:[35]]
gremlin> g.V().has('age').order().by('age',desc).limit(1).valueMap()
==>[name:[peter],age:[35]]
If you really wanted to use max you need to do something like this
gremlin> g.V().values('age').max().as('m').V().where(eq('m')).by('age').by().valueMap()
==>[name:[peter],age:[35]]
gremlin> g.V().values('age').max().as('m').V().where(eq('m')).by('age').by().valueMap()
==>[name:[peter],age:[35]]
For some reason Discord did not show me Stephen's answers until just now - sorry for duplicate answer! I guess it's good we both said the same thing 🙂
danielcraig23
danielcraig23•12mo ago
Thanks Kelvin and Stephen!
Want results from more Discord servers?
Add your server
More Posts
Concurrent MergeV gremlingo - Vertex Id existsIf I use more than one go routine to update the gremlin server, so each has its own connection and tHelp Needed with Sample Method in Gremlin-GoHello Apache TinkerPop Community, I'm currently working on a Go project using the Apache TinkerPop Is it possible to extract the requestId of an Amazon Neptune Gremlin query via gremlin-driver?Is there any way via gremlin-driver to extract the requestId of a completed query submitted to AmazoAggregating vertices with set-cardinality propertiesI am aggregating traversed vertices that have both single and set-cardinality properties. When captuAre the developers of TinkerPop interested in the Performance difference on the equivalent queries?Hi all! I was recently working on generating equivalent Gremlin queries to test TinkerGraph and thenGremlingo with Neptune - Read loop errorCode that works perfectly on my local TinkerPop Gremlin server, fails in a (to me right now anyway ;3.6.2 gremlin-server possible memory leakHas there been any memory leak reports in versions >=3.6.2? I just tracked down a memory leak that gremlin-go, MergeE, and NeptuneI couldn't find a good example for using the MergeE step without having the IDs of the vertices. I'vNo logs getting getting logged in log file for gremlin serverHello , This query is regarding the logs that I am not able to get while the janusgraph server starQuestion on macth stepI am wondering why the following queries return the different results: > gremlin> graph = TinkerFact