Reputation: 1194
I am having list of edges between two vertices having time as edge property key. Eg: A --> B ( time=t1,age=20), A-->B (time=t2,age=30) ...
I need to fetch edges greater than the given time and take the max value of property 'age'
Code Example :
val end_time = System.currentTimeMillis() - duration
val r = graph.V().has(ID, name).outE.filter { it: Edge =>
(it.property(time).value() > end_time)
}
println("r.values("age").max().headOption().get)
this returns in Option[Byte] format.
Is there any better way to do this. Also i need the value in integer.
Upvotes: 1
Views: 2377
Reputation: 2819
First of all, you should avoid using lambdas in general: http://tinkerpop.apache.org/docs/current/reference/#a-note-on-lambdas
You can filter the edges based on a specific minimal value with the following query:
g.V().has('ID', 'a').outE().where(values('time').is(gt(end_time)))
If you now want to get the maximum value of an edge property like age for those edges, you can simply add that to the query:
g.V().has('ID', 'a').outE().where(values('time').is(gt(end_time))).values('age').max()
Upvotes: 4