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); }