首页 > 解决方案 > Gremlin:使用时间戳属性过滤重复边

问题描述

我有不同时间戳的重复边,需要获取最新的时间戳边,我试图通过下面的查询来获取。我无法使用.max(),因为它适用于数字。有没有其他选择?

g.V().has('streamPath','/local/Prod/SupportBI/Prod/Staging/Integration/Chat/MSaaSChatCompleted.ss').as('ParentStream').outE('generate').order().by('timestamp', decr).values('timestamp')

样本输出

[
  "2018-07-10T20:18:57",
  "2018-07-10T20:18:57",
  "2018-07-10T20:16:39",
  "2018-07-10T20:16:39",
  "2018-07-10T20:07:51",
  "2018-07-10T16:18:56",

我的实际查询:

g.V().has('streamPath','/Chat/Completed.ss').as('ParentStream').outE('generate').as('Edges').map(select('Edges').inV()).as ('NextStream').select('ParentStream', 'NextStream','Edges').simplePath()

我得到了重复的边缘(时间戳、jobid、id 不同,属性的重置相同)。需要采用具有最新时间戳的最近边缘。

标签: gremlin

解决方案


如果你有这个:

g.V().has('streamPath','/local/Prod/SupportBI/Prod/Staging/Integration/Chat/MSaaSChatCompleted.ss').as('ParentStream').
  outE('generate').
  order().
    by('timestamp', decr).
  values('timestamp')

您不能添加limit(1)到第一个,因为您首先订购了最近的时间戳吗?

附带说明一下,在 TinkerPop 3.4.0(在此答案时未发布)中,您可以使用max()任何Comparable

gremlin> g.V().values('name').max()
==>vadas

推荐阅读