【问题标题】:How to filter datetime using gremlin_python如何使用 gremlin_python 过滤日期时间
【发布时间】:2021-11-27 09:19:43
【问题描述】:

我想根据日期过滤顶点。我不知道我必须从哪个包中引用 gt

graph = Graph()
remote_connection = DriverRemoteConnection(gremlin, 'g')
g = graph.traversal().withRemote(remote_connection)
serviceAcc=g.V().hasLabel('ServiceAccount').has('creationTime',TextP.gt(datetime.datetime('2021-10-05'))).valueMap(True).toList()
remote_connection.close()

【问题讨论】:

  • @kelvin:当我使用 [from gremlin_python.process.traversal import P] 时,我最终得到异常'{TypeError}需要一个整数(获取类型 str)'。

标签: python gremlin gremlinpython


【解决方案1】:

gtlt 这样的谓词是P 类的一部分。所以你会使用P.gt

更新以在 2021 年 10 月 26 日显示示例

使用连接到 Gremlin 服务器(本例中为 Amazon Neptune)的 Python 控制台

>>> import datetime

>>> g.addV('now').property('date',datetime.datetime(2021,10,25,19,41,0)).next()

v[3ebe5ef4-512a-a2e1-e519-34583b96dd1c]

>>> g.V().has('date',P.gte(datetime.datetime(2021,10,25,19,0,0))).next()

v[3ebe5ef4-512a-a2e1-e519-34583b96dd1c]

>>> g.V().has('date',P.gte(datetime.datetime(2021,10,25,19,0,0))).valueMap().next()

{'date': [datetime.datetime(2021, 10, 25, 19, 41)]}

【讨论】:

  • 当我使用 [from gremlin_python.process.traversal import P] 时,我最终得到了异常'{TypeError}一个整数是必需的(得到类型 str)'。
  • Python datetime 正在寻找一种稍微不同的格式,而不是 ISO 8601 字符串。供参考docs.python.org/3/library/datetime.html
  • 我更新了答案以显示示例。
猜你喜欢
  • 2021-04-28
  • 2020-08-03
  • 2019-11-07
  • 2017-09-06
  • 2022-07-16
  • 1970-01-01
  • 2021-10-09
  • 2022-11-28
  • 2020-04-27
相关资源
最近更新 更多