new to gremlin and I've been having trouble filtering vertices by a max value.
the simple graph looks something like this:
source.addV("x").property("id", "1").property("version", 1.0)
.addV("x").property("id", "1").property("version", 1.1)
.addV("x").property("id", "2").property("version", 1.0)
My query looks like this:
source.V()
.has(T.label, "x")
.group()
.by("id").unfold().where(select(Column.values).unfold().values("version").max())
Output i'm looking for would be
[{type:x, id:1, version:1.1}, {type:x, id:2, version:1.0}]
my issue is its throwing:
org.apache.tinkerpop.gremlin.driver.exception.ResponseException: {"requestId":"x","code":"InternalFailureException","detailedMessage":"null:select([null])"}
any help would be appreciated. Thanks.
There are a couple of things going on here.
First, you are adding vertices without a label which while allowed is not a very common practice. You usually want to group like items together by the vertex label. You can add a vertex label to your traversal by putting the label name inside the addV() step like this:
g.addV("labelname")
Second, you are adding the version properties as strings instead of as numbers, which is what I assume you actually want as max() of a string is not really meaningful. To change this remove the quotes from around the version number like this:
g.addV().property("type", "x").property("id", "1").property("version", 1.0)
Third, the way to think about this problem is a bit different then you might expect. Instead of trying to find the max version number and comparing all the traversers against it the way to think about this problem is "Find me the vertex with the highest version, then for each vertex see if it's version number is equal". It is a bit difficult to wrap your head around this but here is a traversal that demonstrates how to do this:
g.V().
order().
by('version', desc).
limit(1).as('b').
V().as('a').
where('a', eq('b')).
by('version')
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With