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 ffe30dcd9..35a76a070 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 @@ -492,21 +492,19 @@ public class HoodieCopyOnWriteTable extends Hoodi */ @Override public List clean(JavaSparkContext jsc) { - List partitionCleanStats; try { List partitionsToClean = FSUtils.getAllPartitionPaths(getFs(), getMetaClient().getBasePath(), config.shouldAssumeDatePartitioning()); logger.info("Partitions to clean up : " + partitionsToClean + ", with policy " + config .getCleanerPolicy()); - partitionCleanStats = cleanPartitionPaths(partitionsToClean, jsc); if (partitionsToClean.isEmpty()) { logger.info("Nothing to clean here mom. It is already clean"); - return partitionCleanStats; + return Collections.emptyList(); } + return cleanPartitionPaths(partitionsToClean, jsc); } catch (IOException e) { throw new HoodieIOException("Failed to clean up after commit", e); } - return partitionCleanStats; } private static class PartitionCleanStat implements Serializable { diff --git a/hoodie-client/src/test/java/com/uber/hoodie/TestHoodieClient.java b/hoodie-client/src/test/java/com/uber/hoodie/TestHoodieClient.java index 61ff10af5..41c9c02ea 100644 --- a/hoodie-client/src/test/java/com/uber/hoodie/TestHoodieClient.java +++ b/hoodie-client/src/test/java/com/uber/hoodie/TestHoodieClient.java @@ -1225,6 +1225,28 @@ public class TestHoodieClient implements Serializable { assertTrue(HoodieTestUtils.doesDataFileExist(basePath, partitionPaths[0], "001", file2P0C1)); } + @Test + public void testCleaningWithZeroPartitonPaths() throws IOException { + HoodieWriteConfig config = HoodieWriteConfig.newBuilder().withPath(basePath) + .withAssumeDatePartitioning(true) + .withCompactionConfig(HoodieCompactionConfig.newBuilder() + .withCleanerPolicy(HoodieCleaningPolicy.KEEP_LATEST_COMMITS) + .retainCommits(2).build()).build(); + + // Make a commit, although there are no partitionPaths. + // Example use-case of this is when a client wants to create a table + // with just some commit metadata, but no data/partitionPaths. + HoodieTestUtils.createCommitFiles(basePath, "000"); + + HoodieTable table = HoodieTable + .getHoodieTable(new HoodieTableMetaClient(FSUtils.getFs(), config.getBasePath(), true), + config); + + List hoodieCleanStatsOne = table.clean(jsc); + assertTrue("HoodieCleanStats should be empty for a table with empty partitionPaths", + hoodieCleanStatsOne.isEmpty()); + } + @Test public void testCleaningSkewedPartitons() throws IOException { HoodieWriteConfig config = HoodieWriteConfig.newBuilder().withPath(basePath)