英文:
How to stream records by batch with neo4j java driver 4.0.0?
问题
假设我有一个查询发送到neo4j存储过程,应该返回 100,000 条记录。我想要的是以每批 1000 条的方式获取我的记录。我不想等待所有 100,000 条记录都被 Neo4j 发送过来,我想在客户端控制接收的记录数量。我注意到在 ResultCursor
中有一个 CompletionStage<Record> nextAsync()
方法,它实现了我想要的功能,但一次只返回一条记录。这并不是最优解,因为它需要在客户端和 Neo4j 之间进行过多的往返以获取所有记录。是否有一种方法可以请求接下来的 N 条记录?
我正在使用 neo4j java driver 4.0.0 版本的异步模式。
英文:
Let's say I have a query to a neo4j procedure which should return 100 000 records.
What I would like is a way to get my records by batches of 1000. I don't want to wait for the 100 000 records to be all sent by Neo4j, I would like to control on client side the number of records I receive. I have noticed there is a CompletionStage<Record> nextAsync()
method in ResultCursor
, which is doing what I want, but only one record by one. This is not optimal, as it would need too many round trips between the client and neo4j to get all the records. Is there a way to ask for the next N records ?
I am using neo4j java driver 4.0.0 in async mode.
答案1
得分: 0
[已更新]
在 neo4j 4.0+ 中,nextAsync()
方法在内部为您按批次获取记录。
其实现会从一个异步补充的队列中返回每个记录,以批次方式进行,只要队列大小低于一个低水位线。
因此,nextAsync()
方法非常高效,通常可以从队列中非常快地获取下一个记录。
英文:
[UPDATED]
In neo4j 4.0+, the nextAsync()
method internally gets the records in batches for you.
Its implementation returns each record from a queue that is asynchronously replenished, in batches, whenever the queue size falls below a low watermark.
So, the nextAsync()
method is pretty optimal and should normally get the next record very quickly from the queue.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论