简体   繁体   English

Gremlin查询(AWS Neptune)中的减法

[英]Subtraction in a Gremlin Query (AWS Neptune)

I am trying to create a gremlin query for AWS Neptune which checks for a particular property on a node (lastUpdated) and returns all nodes that have value smaller than a certain number. 我正在尝试为AWS Neptune创建一个gremlin查询 ,该查询检查节点上的特定属性(lastUpdated)并返回值小于某个数字的所有节点。 lastUpdated is epoch timestamp in this case, and I am trying to find all nodes which have lastUpdated 90 days less than current timestamp. lastUpdated在这种情况下是epoch时间戳,我试图找到lastUpdated比当前时间戳少90天的所有节点。

Here is the query that I wrote: 这是我写的查询:

g.V().hasLabel('nodelabel').hasNot('lastUpdated',P.gt(1544916150)).count()

To make this query dynamic, so that whenever it is fired, I get all nodes more than 90 days old, I changed it to following: 为了使此查询动态化,以便每当触发该查询时,我都会使所有节点的使用时间超过90天,因此将其更改为以下内容:

g.V().hasLabel('nodelabel').has('lastUpdated',not(P.gt(1552798296-7776000))).count()

where 1552798296 is current_date and 7776000 is number of seconds in 90 days 其中1552798296是current_date,而7776000是90天的秒数

Apparently, subtraction is not that straightforward in Gremlin. 显然,减法在Gremlin中并不那么简单。 Any hints/suggestions on how I can write this gremlin query? 关于如何编写这个gremlin查询的任何提示/建议?

Thanks 谢谢

TinkerPop introduced a math() step a few point releases back. TinkerPop引入了math()步骤,之后又发布了一些内容。

You could do something like this: 你可以这样做:

gremlin> g.V().has('n').valueMap(true)
==>[id:58855,label:test,n:[5]]
==>[id:58857,label:test,n:[10]]  

gremlin> g.V().values('n')
==>5
==>10

gremlin> g.V().values('n').math('_ -5')
==>0.0
==>5.0

gremlin> g.V().where(values('n').math('_ -5').is(gt(0)))
==>v[58857]   

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM