正确处理 Gremlin 中的日期操作

Proper handling of date operations in Gremlin

我正在使用 AWS Neptune Gremlin 和 gremlin_python

我在 属性 中的日期存储为 Neptune specs 中要求的日期时间。

我使用 Python 这样的代码创建了它:
properties_dict['my_date'] = datetime.fromtimestamp(my_date, timezone.utc)
然后构造具有属性的顶点:

for prop in properties:
    query += """.property("%s", "%s")"""%(prop, properties[prop])

稍后与构建的图交互时,我只能通过如下所示的精确字符串匹配查询找到顶点:
g.V().hasLabel('Object').has("my_date", "2017-12-01 00:00:00+00:00").valueMap(True).limit(3).toList()

在 Gremlin 中处理日期或日期时间的最佳方式是什么?
如何进行范围查询,例如 "give me all Vertices that have date in year 2017"?

就我个人而言,我更喜欢将 date/time 值存储为 days/seconds/milliseconds 纪元以来的值。这绝对适用于任何图形数据库,并使范围查询变得更加简单。此外,自纪元以来到天数或秒数的转换应该是几乎任何语言的简单方法调用。

因此,当您创建属性字典时,您可以通过将其更改为来简化代码:

properties_dict['my_date'] = my_date

... 因为 my_date 应该代表自纪元以来的秒数。范围查询将像这样简单:

g.V().has("Object", "my_date", P.between(startTimestamp, endTimestamp)).
  limit(3).valueMap(True)