如何使用 Neo4j Java 驱动程序 4.0.0 逐批流式传输记录?

huangapple go评论87阅读模式
英文:

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&lt;Record&gt; 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.

huangapple
  • 本文由 发表于 2020年3月4日 03:41:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/60514397.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定