diff --git standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/Warehouse.java standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/Warehouse.java index da5a71cc64..0117d1512d 100755 --- standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/Warehouse.java +++ standalone-metastore/src/main/java/org/apache/hadoop/hive/metastore/Warehouse.java @@ -371,8 +371,12 @@ public void recycleDirToCmPath(Path f, boolean ifPurge) throws MetaException { } public boolean isEmpty(Path path) throws IOException, MetaException { - ContentSummary contents = getFs(path).getContentSummary(path); - if (contents != null && contents.getFileCount() == 0 && contents.getDirectoryCount() == 1) { + try { + ContentSummary contents = getFs(path).getContentSummary(path); + if (contents != null && contents.getFileCount() == 0 && contents.getDirectoryCount() == 1) { + return true; + } + } catch(FileNotFoundException fnfe) { return true; } return false; diff --git standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDropPartitions.java standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDropPartitions.java index 9037001504..d077989400 100644 --- standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDropPartitions.java +++ standalone-metastore/src/test/java/org/apache/hadoop/hive/metastore/client/TestDropPartitions.java @@ -24,10 +24,9 @@ import java.util.List; import java.util.Map; +import org.apache.hadoop.fs.FileSystem; import org.apache.hadoop.fs.Path; -import org.apache.hadoop.hive.metastore.IMetaStoreClient; -import org.apache.hadoop.hive.metastore.MetaStoreTestUtils; -import org.apache.hadoop.hive.metastore.PartitionDropOptions; +import org.apache.hadoop.hive.metastore.*; import org.apache.hadoop.hive.metastore.annotation.MetastoreCheckinTest; import org.apache.hadoop.hive.metastore.api.Catalog; import org.apache.hadoop.hive.metastore.api.Database; @@ -289,6 +288,21 @@ public void testDropPartitionEmptyVal() throws Exception { client.dropPartition(DB_NAME, TABLE_NAME, partVals, false); } + @Test(expected = NoSuchObjectException.class) + public void testDropPartitionNonExistingParentPath() throws Exception { + createPartition(Lists.newArrayList("2019", "july"), getYearAndMonthPartCols()); + String location = client.getPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("2019", "july")).getSd().getLocation(); + boolean b = deleteParentPath(new Path(location)); + Assert.assertTrue(b); + client.dropPartition(DB_NAME, TABLE_NAME, Lists.newArrayList("2019", "july"), true); + } + + private boolean deleteParentPath( Path path) throws Exception{ + Warehouse wh = new Warehouse(metaStore.getConf()); + FileSystem fs = wh.getFs(path); + return fs.deleteOnExit(path.getParent()); + } + @Test(expected = MetaException.class) public void testDropPartitionMoreValsInList() throws Exception {