diff --git ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java index 02cea7c722cc2c319f3fa291bde7f0c83d23a8c7..d661f10c407776a9123d074b3cf3dbcb1d5f0508 100644 --- ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java +++ ql/src/java/org/apache/hadoop/hive/ql/metadata/Hive.java @@ -1781,6 +1781,16 @@ public Partition loadPartition(Path loadPath, Table tbl, // In that case, we want to retry with alterPartition. LOG.debug("Caught AlreadyExistsException, trying to alter partition instead"); setStatsPropAndAlterPartition(hasFollowingStatsTask, tbl, newTPart); + } catch (Exception e) { + try { + final FileSystem newPathFileSystem = newPartPath.getFileSystem(this.getConf()); + boolean isAutoPurge = "true".equalsIgnoreCase(tbl.getProperty("auto.purge")); + final FileStatus status = newPathFileSystem.getFileStatus(newPartPath); + Hive.trashFiles(newPathFileSystem, new FileStatus[] {status}, this.getConf(), isAutoPurge); + } catch (IOException io) { + LOG.error("Could not delete partition directory contents after failed partition creation: ", io); + } + throw e; } } else { setStatsPropAndAlterPartition(hasFollowingStatsTask, tbl, newTPart);