Stream results instead of fetching the entire set

This commit is contained in:
Bart Broere committed 2026-11-04 14:34:57 +01:00
1 parent eb989c9155
commit dc978fd0fd
9 files changed
+324 -22

No files matched your search

+26
View File
@@ -91,6 +91,26 @@ MATCH ()-[]->() RETURN { name:'relationships', data: count(*)} AS result
rows = list(s.run("UNWIND range(1, 2500) AS i RETURN i"))
check("large result over several PULLs", len(rows) == 2500 and rows[-1]["i"] == 2500)
rows = [r["i"] for r in s.run("UNWIND range(1, 2500) AS i RETURN i ORDER BY i")]
check("rows in order across batches", rows == list(range(1, 2501)))
s.run("UNWIND range(1, 5) AS i CREATE (n:Discarded {i: i}) RETURN n.i").consume()
check("discarded result of a write still writes",
s.run("MATCH (n:Discarded) RETURN count(n) AS c").single()["c"] == 5)
s.run("MATCH (n:Discarded) DELETE n RETURN 1").consume()
check("write keyword in a string is a read",
s.run("RETURN 'SET' AS v").consume().query_type == "r")
rows = []
try:
for r in s.run("UNWIND range(1, 1500) AS i RETURN 1 / (1500 - i) AS v"):
rows.append(r["v"])
check("error after the first batch is reported", False)
except neo4j.exceptions.Neo4jError:
check("error after the first batch is reported", len(rows) >= 1000)
check("recovers after error in a later batch", s.run("RETURN 1 AS x").single()["x"] == 1)
check("string escaping roundtrip",
s.run("RETURN $v AS v", v="a'b\\c\n\"d\" $x").single()["v"] == "a'b\\c\n\"d\" $x")
check("map/list params",
@@ -117,6 +137,12 @@ MATCH ()-[]->() RETURN { name:'relationships', data: count(*)} AS result
check("managed write transaction", s.execute_write(work) == 1)
def read_your_writes(tx):
tx.run("CREATE (:Temp {n: 3}) RETURN 1")
return tx.run("UNWIND range(1, 1500) AS i MATCH (n:Temp {n: 3}) RETURN i").value()
check("query sees an earlier write in its transaction", len(s.execute_write(read_your_writes)) == 1500)
with driver.session(database="system") as s:
s.run(f"DROP DATABASE {GRAPH}").consume()