neo4j-contrib / py2neo

EOL! Py2neo is a comprehensive Neo4j driver library and toolkit for Python.
https://py2neo.org
Apache License 2.0
22 stars 7 forks source link

using py2neo to run Neo4j Graph Data Science (GDS) library queries does not return all results #837

Closed bucweat closed 4 years ago

bucweat commented 4 years ago

Hi,

I've been spending some time lately learning Neo4J and py2neo. I'm currently learning about the GDS library by running the examples in Chapter 4. Pathfinding and Graph Search Algorithms of Graphing Algorithms book on O'Reilly (Safari Link requires login, you can also get the book via Neo4J for free at this link). The cypher query looks something like this:

    MATCH (source:Place {id: "Amsterdam"}),
          (destination:Place {id: "London"})
    CALL gds.alpha.shortestPath.stream({
      startNode: source,
      endNode: destination,
      nodeProjection: "*",
      relationshipProjection: {
        all: {
          type: "*",
          properties: "distance",
          orientation:  "UNDIRECTED"
        }
      },
      relationshipWeightProperty: "distance"
    })
    YIELD nodeId, cost
    RETURN gds.util.asNode(nodeId).id AS place, cost;

When I run this in Neo4J desktop, I get back the expected answer mentioned in the book that has 7 rows. When I run in py2neo using graph.run() I only get back 3 rows. I've tried this with some other cypher queries using other GDS algorithms, all of which should return more than 3 row, but with py2neo I always get back just 3 rows. When I run cypher queries without the GDS I always get the expected number of rows, even results with hundreds of rows.

So is there something special that I need to consider when running GDS in py2neo? I thought maybe there was a timeout issues but I can't find anything and am scratching my head...

Just an FYI I did try with with the official BOLT driver and I got the expected 7 rows.

technige commented 4 years ago

I assume from your description that you are only reading the preview text, and not iterating through the entire result. Cursor preview displays up to three records, not the entire result. You will need to instead step through each of those records by using the cursor.