繁体   English   中英

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

[英]Unexpected Count & Filter Behaviour in AWS Neptune

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

可以使用以下代码重新创建此错误(在我的例子中使用Gremlin-Python 3.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 版本 1.1.1.0中修复的错误。

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

(感谢 Neptune 团队的修复!)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM