【问题标题】:Gremlin with Neptune: filter edges using math result with previous edge valueGremlin with Neptune:使用具有先前边缘值的数学结果过滤边缘
【发布时间】:2021-10-25 16:36:15
【问题描述】:

我有以下图表:

我想解决以下遍历:

  1. 从节点“abc-01-05”开始
  2. 转到主“ip”节点(id:abc)
  3. 从 ip 节点遍历出边,其中日期“at_millis”小于第 2 步中遍历的边 + 1 天
  4. 结果应该是节点:abc-01-05 和 abc-02-05

我能做的最好的查询是基于this response,但不起作用:

g.V('abc-01-05')
    .outE('related_to').as_('saved_edge')
    .inV()
    .inE('related_to')
    .where(
        P.lte('saved_edge')
    )
    .by('at_millis')
    .by(__.math('saved_edge + 86400001').by('at_millis'))
    .toList()

这会返回这个错误:

GremlinServerError: 500: {"requestId":"3aaaca37-75eb-4650-b111-130c6e65b040","code":"InternalFailureException","detailedMessage":"Exception processing a script on request [RequestMessage{, requestId=3aaaca37-75eb-4650-b111-130c6e65b040, op='bytecode', processor='traversal', args={gremlin=[[], [V(abc-01-05), outE(related_to), as(saved_edge), inV(), inE(related_to), where(lte(saved_edge)), by(at_millis), by([[], [math(saved_edge + 86400001), by(at_millis)]])]], aliases={g=g}}}]."}

任何帮助都会非常有帮助!谢谢!

【问题讨论】:

    标签: gremlin amazon-neptune


    【解决方案1】:

    添加另一个答案只是为了指出您在原始查询中看到的错误是因为需要反转 by 步骤。第二个by 调制器应用于where 步骤中的标签。第一个by 调制器定义了它将与什么进行比较。此外,为了使测试正常工作,被测试的值需要稍作调整。这是原始查询的工作版本。

    g.V('abc-01-05')
        .outE('related_to').as('saved_edge')
        .inV()
        .inE('related_to').as('related')
        .where(P.lte('related'))
          .by(__.math('saved_edge + 86400000').by('at_millis'))
          .by('at_millis')
    

    【讨论】:

    • 这以更简单的方式解决了我的问题,因此我将其更改为已接受的答案,谢谢!
    【解决方案2】:

    一种方法:

    g.V('abc-01-05').
      outE('related_to').as('saved_edges').
      values('at_millis').as('a1').
      math('a1 + 86400001').as('saved_edges_millis_plus_1_day').
      select('saved_edges').
      inV().
      inE('related_to').as('intermediate_edges').
      values('at_millis').
      where(P.lt('saved_edges_millis_plus_1_day')).
      select('intermediate_edges')
    

    【讨论】:

    • 这会返回正确过滤的值,但我需要具有 at_millis 属性的实际边缘,而不是值。
    • 编辑了结果边缘的答案。
    猜你喜欢
    • 2019-03-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-02-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-20
    相关资源
    最近更新 更多