Skip to content

Commit

Permalink
Fixed batches being shifted by one in arrow.export (#693)
Browse files Browse the repository at this point in the history
  • Loading branch information
JoelBergstrand authored Nov 27, 2024
1 parent 18e352d commit 5018823
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void updateRunningBatch(ProgressInfo progressInfo) {

@Override
public void done() {
if (totalEntities / batchSize == lastBatch) lastBatch++;
if (totalEntities % batchSize != 0) lastBatch++;
updateRunningBatch(progressInfo);
progressInfo.done(start);
if (consumer != null) {
Expand Down
25 changes: 25 additions & 0 deletions core/src/test/java/apoc/export/arrow/ArrowTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -147,6 +147,10 @@ private String extractFileName(Result result) {
return result.<String>columnAs("file").next();
}

private Long extractBatches(Result result) {
return result.<Long>columnAs("batches").next();
}

private <T> T readValue(String json, Class<T> clazz) {
if (json == null) return null;
try {
Expand Down Expand Up @@ -378,6 +382,27 @@ public void testFileVolumeArrowAll() {
db.executeTransactionally("MATCH (n:ArrowNode) DELETE n");
}

@Test
public void testArrowCorrectBatchCount() {
// given - when
db.executeTransactionally("UNWIND range(0, 10000 - 1) AS id CREATE (:ArrowNode{id:id})");

Long batchesOdd = db.executeTransactionally(
"CALL apoc.export.arrow.query('batchCount_test.arrow', 'MATCH (n:ArrowNode) RETURN n.id AS id', {batchSize: 3}) YIELD batches",
Map.of(),
this::extractBatches);

Long batchesEven = db.executeTransactionally(
"CALL apoc.export.arrow.query('batchCount_test.arrow', 'MATCH (n:ArrowNode) RETURN n.id AS id', {batchSize: 2}) YIELD batches",
Map.of(),
this::extractBatches);

// then
assertEquals(3334, batchesOdd.longValue());
assertEquals(5000, batchesEven.longValue());
db.executeTransactionally("MATCH (n:ArrowNode) DELETE n");
}

@Test
public void testValidNonStorableQuery() {
final List<byte[]> list = db.executeTransactionally(
Expand Down

0 comments on commit 5018823

Please sign in to comment.