AWS Neptune 中的意外计数和筛选行为

Unexpected Count & Filter Behaviour in AWS Neptune

我遇到一些 gremlin 查询的意外 StopIteration 错误,这些查询在嵌套 filter 个步骤中包含 count 个步骤。

可以使用以下代码重现此错误(在我的例子中使用 Gremlin-Python3.5.0):

filter_header = g.addV().id().next()
count_headers = [g.addV().id().next() for _ in range(10)]

for i, c in enumerate(count_headers):
    # Add 10 nodes
    sub_nodes = [g.addV().id().next() for _ in range(10)]
    # Connect them all to the header
    for s in sub_nodes:
        g.V(c).addE('edge').to(__.V(s)).iterate()
    # Connect i of them to the filter header
    for s in sub_nodes[:i]:
        g.V(filter_header).addE('edge').to(__.V(s)).iterate()

# This raises StopIterationError
g.V(count_headers).filter(
    __.out('edge').filter(
        __.in_('edge').hasId(filter_header)
    ).count().is_(P.gt(1))
).count().next()

(等效于如果使用 toList 而不是 next 我得到一个空列表)

但是,如果您在 count:

之后 unfold,则不会发生此错误
# No StopIterationError
g.V(count_headers).filter(
    __.out('edge').filter(
        __.in_('edge').hasId(filter_header)
    ).count().unfold().is_(P.gt(1))
).count().next()

如果您使用 map 而不是 filter 也不会发生:

# No StopIterationError
g.V(count_headers).as_('c').map(
    __.out('edge').filter(
        __.in_('edge').hasId(filter_header)
    ).count().is_(P.gt(1))
).select('c').count().next()

我已经测试过,使用 TinkerGraph 时不会发生此错误,所以我怀疑这是 AWS Neptune 特有的。

我真的很感激任何关于为什么会发生这种情况的指导,如果我做错了什么,或者有什么不同意味着这只发生在海王星。或者 - 如果一致认为这是一个错误 - 如果有人能让我知道在哪里提出它,我将不胜感激。

当使用 Gremlin 客户端时,例如 Gremlin Python,如果查询没有结果,next 步骤将抛出错误。我更喜欢始终使用 toList ,因为这样可以保证至少得到一个空列表。如果您通过 Gremlin 控制台在本地使用 TinkerGraph,您将不会看到相同的行为。如果没有结果也是意想不到的,那就是第二个要探索的项目。

作为 Python next 行为的示例,这是一个使用 Python 控制台的简单实验。如果您 运行 使用由 TinkerGraph 支持的 Gremlin 服务器进行相同的测试,您将看到相同的结果。


>>> g.V().hasId('I do not exist').next()

Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/home/ec2-user/.local/lib/python3.6/site-packages/gremlin_python/process/traversal.py", line 89, in next
    return self.__next__()
  File "/home/ec2-user/.local/lib/python3.6/site-packages/gremlin_python/process/traversal.py", line 50, in __next__
    self.last_traverser = next(self.traversers)
StopIteration

对于发现自己在这里的任何人:这是一个已在 Neptune Engine release 1.1.1.0 中修复的错误。

“修复了一个罕见的 Gremlin 错误,该错误在组合使用嵌套 filter() 和 count() 步骤时未返回任何结果”

(感谢Neptune团队修复!)