2

我正在尝试gds.alpha.allShortestPaths.stream在一个py2neo.Graph实例中运行

那是我的代码:

cypherCode = """CALL gds.alpha.allShortestPaths.stream({
nodeQuery: 'MATCH (n:AUTHOR) RETURN id(n) AS id',
relationshipQuery: 'MATCH (n:AUTHOR)-[r:COAUTHORS]-(p:AUTHOR) RETURN id(n) AS source, id(p) AS target'
})
YIELD sourceNodeId, targetNodeId, distance
return sourceNodeId, targetNodeId, distance
"""
r = graph.run(cypherCode)

我正在使用relationshipQuery: 'MATCH (n:AUTHOR)-[r:COAUTHORS]-(p:AUTHOR) RETURN id(n) AS source, id(p) AS target'因为我需要无向路径。

60 秒后,我收到此错误:

IndexError: index out of range
---------------------------------------------------------------------------
IndexError                                Traceback (most recent call last)
<timed exec> in <module>

~/.local/lib/python3.8/site-packages/py2neo/database.py in run(self, cypher, parameters, **kwparameters)
    403         :return:
    404         """
--> 405         return self.auto().run(cypher, parameters, **kwparameters)
    406 
    407     def evaluate(self, cypher, parameters=None, **kwparameters):

~/.local/lib/python3.8/site-packages/py2neo/database.py in run(self, cypher, parameters, **kwparameters)
    976                 result = self._connector.run(self.ref, cypher, parameters)
    977             else:
--> 978                 result = self._connector.auto_run(cypher, parameters,
    979                                                   graph_name=self.graph.name,
    980                                                   readonly=self.readonly)

~/.local/lib/python3.8/site-packages/py2neo/client/__init__.py in auto_run(self, cypher, parameters, pull, graph_name, readonly)
   1341             if pull != 0:
   1342                 try:
-> 1343                     cx.pull(result, n=pull)
   1344                 except TypeError:
   1345                     # If the RUN fails, so will the PULL, due to

~/.local/lib/python3.8/site-packages/py2neo/client/bolt.py in pull(self, result, n, capacity)
    941         result.append(response, final=(n == -1))
    942         try:
--> 943             self._sync(response)
    944         except BrokenWireError as error:
    945             result.transaction.mark_broken()

~/.local/lib/python3.8/site-packages/py2neo/client/bolt.py in _sync(self, *responses)
    745         self.send()
    746         for response in responses:
--> 747             self._wait(response)
    748 
    749     def _audit(self, task):

~/.local/lib/python3.8/site-packages/py2neo/client/bolt.py in _wait(self, response)
    740         """
    741         while not response.full() and not response.done():
--> 742             self._fetch()
    743 
    744     def _sync(self, *responses):

~/.local/lib/python3.8/site-packages/py2neo/client/bolt.py in _fetch(self)
    715         failed state into an exception.
    716         """
--> 717         tag, fields = self.read_message()
    718         if tag == 0x70:
    719             self._responses.popleft().set_success(**fields[0])

~/.local/lib/python3.8/site-packages/py2neo/client/bolt.py in read_message(self)
    642 
    643     def read_message(self):
--> 644         tag, fields = self._reader.read_message()
    645         if tag == 0x71:
    646             # If a RECORD is received, check for more records

~/.local/lib/python3.8/site-packages/py2neo/client/bolt.py in read_message(self)
     94                 chunks.append(self.wire.read(size))
     95         message = b"".join(chunks)
---> 96         _, n = divmod(message[0], 0x10)
     97         try:
     98             unpacker = UnpackStream(message, offset=2)

IndexError: index out of range

当我尝试更改relationshipQuery带有方向的路径或使用小图时,它工作正常。

直接在 neo4j 浏览器上运行这个密码代码,它可以工作,运行大约需要 80 秒。

我的图表有 10k 个节点和 20k 个关系。

4

0 回答 0