Index: metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java =================================================================== --- metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (revision 723272) +++ metastore/src/java/org/apache/hadoop/hive/metastore/HiveMetaStore.java (working copy) @@ -340,6 +340,11 @@ } } + /** + * Is this an external table? + * @param table Check if this table is external. + * @return True if the table is external, otherwise false. + */ private boolean isExternal(Table table) { if(table == null) { return false; @@ -480,6 +485,7 @@ LOG.info("Partition values:" + part_vals); boolean success = false; Path partPath = null; + Table tbl = null; try { getMS().openTransaction(); Partition part = this.get_partition(db_name, tbl_name, part_vals); @@ -494,12 +500,15 @@ } success = getMS().commitTransaction(); partPath = new Path(part.getSd().getLocation()); + tbl = get_table(db_name, tbl_name); } finally { if(!success) { getMS().rollbackTransaction(); } else if(deleteData && (partPath != null)) { - wh.deleteDir(partPath, true); - // ok even if the data is not deleted + if(tbl != null && !isExternal(tbl)) { + wh.deleteDir(partPath, true); + // ok even if the data is not deleted + } } } return true; Index: metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java =================================================================== --- metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java (revision 723272) +++ metastore/src/test/org/apache/hadoop/hive/metastore/TestHiveMetaStore.java (working copy) @@ -125,6 +125,7 @@ part.setParameters(new HashMap()); part.setSd(tbl.getSd()); part.getSd().setSerdeInfo(tbl.getSd().getSerdeInfo()); + part.getSd().setLocation(tbl.getSd().getLocation() + "/part1"); Partition retp = client.add_partition(part); assertNotNull("Unable to create partition " + part, retp); @@ -132,8 +133,13 @@ Partition part2 = client.getPartition(dbName, tblName, part.getValues()); assertTrue("Partitions are not same",part.equals(part2)); + FileSystem fs = FileSystem.get(this.hiveConf); + Path partPath = new Path(part2.getSd().getLocation()); + + assertTrue(fs.exists(partPath)); ret = client.dropPartition(dbName, tblName, part.getValues(), true); assertTrue(ret); + assertFalse(fs.exists(partPath)); // add the partition again so that drop table with a partition can be tested retp = client.add_partition(part); @@ -143,7 +149,17 @@ ret = client.dropType(typeName); assertTrue("Unable to drop type " + typeName, ret); - + + //recreate table as external, drop partition and it should + //still exist + tbl.setParameters(new HashMap()); + tbl.getParameters().put("EXTERNAL", "TRUE"); + client.createTable(tbl); + retp = client.add_partition(part); + assertTrue(fs.exists(partPath)); + client.dropPartition(dbName, tblName, part.getValues(), true); + assertTrue(fs.exists(partPath)); + ret = client.dropDatabase(dbName); assertTrue("Unable to create the databse " + dbName, ret); } catch (Exception e) {