[英]gremlin filtering out edges based on time and fetch max value
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) ...例如: 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.这以Option[Byte]格式返回。
Is there any better way to do this.有没有更好的方法来做到这一点。 Also i need the value in integer.我也需要整数值。
First of all, you should avoid using lambdas in general: http://tinkerpop.apache.org/docs/current/reference/#a-note-on-lambdas首先,您应该避免在一般情况下使用 lambdas: 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()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.