正确处理Gremlin中的日期运算

编程入门 行业动态 更新时间:2024-10-18 18:18:33
本文介绍了正确处理Gremlin中的日期运算的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将AWS Neptune Gremlin与 gremlin_python 一起使用。

I am using AWS Neptune Gremlin with gremlin_python.

我在属性中的日期根据需要存储为datetime在 Neptune规范中。

My date in property is stored as datetime as required in Neptune specs.

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

I created it using Python code like this: properties_dict['my_date'] = datetime.fromtimestamp(my_date, timezone.utc) and then constructed the Vertex with properties:

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

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

Later when interacting with the constructed graph, I am only able to find the vertices by an exact string matching query like the following: g.V().hasLabel('Object').has("my_date", "2017-12-01 00:00:00+00:00").valueMap(True).limit(3).toList()

在Gremlin中处理日期或日期时间的最佳方法是什么? 如何我会进行范围查询,例如给我所有日期为2017年的顶点 ?

What's the best way for dealing with date or datetime in Gremlin? How can I do range queries such as "give me all Vertices that have date in year 2017"?

推荐答案

个人而言,我更喜欢将日期/时间值存储为自时代以来的天/秒/毫秒。这绝对可以在任何Graph DB上使用,并使范围查询更加简单。此外,转换到历元后的天数或秒数应该是几乎任何语言的简单方法调用。

Personally, I prefer to store date/time values as days/seconds/milliseconds since epoch. This will definitely work on any Graph DB and makes range queries much simpler. Also, the conversion to days or seconds since epoch and back should be a simple method call in pretty much any language.

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

So, when you create your properties dictionary, you could simplify your code by changing it to:

properties_dict['my_date'] = my_date

...作为 my_date 应该代表自纪元以来的秒数。范围查询将非常简单:

... as my_date should represent the number of seconds since epoch. And a range query would be as simple as:

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

更多推荐

正确处理Gremlin中的日期运算

本文发布于:2023-11-24 04:39:17,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1624003.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:正确处理   日期   Gremlin

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!