From e83dde3b9591d0ff52c453331e80a5d6ae91bb11 Mon Sep 17 00:00:00 2001 From: Nishith Agarwal Date: Mon, 26 Nov 2018 23:17:32 -0800 Subject: [PATCH] Returning empty Statues for an empty spark partition caused due to incorrect bin packing --- .../com/uber/hoodie/table/HoodieCopyOnWriteTable.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/hoodie-client/src/main/java/com/uber/hoodie/table/HoodieCopyOnWriteTable.java b/hoodie-client/src/main/java/com/uber/hoodie/table/HoodieCopyOnWriteTable.java index fc6dcf904..0a7eeaeca 100644 --- a/hoodie-client/src/main/java/com/uber/hoodie/table/HoodieCopyOnWriteTable.java +++ b/hoodie-client/src/main/java/com/uber/hoodie/table/HoodieCopyOnWriteTable.java @@ -176,6 +176,11 @@ public class HoodieCopyOnWriteTable extends Hoodi public Iterator> handleUpdate(String commitTime, String fileId, Iterator> recordItr) throws IOException { + // This is needed since sometimes some buckets are never picked in getPartition() and end up with 0 records + if (!recordItr.hasNext()) { + logger.info("Empty partition with fileId => " + fileId); + return Collections.singletonList((List) Collections.EMPTY_LIST).iterator(); + } // these are updates HoodieMergeHandle upsertHandle = getUpdateHandle(commitTime, fileId, recordItr); return handleUpdateInternal(upsertHandle, commitTime, fileId); @@ -235,6 +240,11 @@ public class HoodieCopyOnWriteTable extends Hoodi public Iterator> handleInsert(String commitTime, Iterator> recordItr) throws Exception { + // This is needed since sometimes some buckets are never picked in getPartition() and end up with 0 records + if (!recordItr.hasNext()) { + logger.info("Empty partition"); + return Collections.singletonList((List) Collections.EMPTY_LIST).iterator(); + } return new CopyOnWriteLazyInsertIterable<>(recordItr, config, commitTime, this); }