if (dropTbl.getPartSpecs() == null) {
// drop the table
db.dropTable(MetaStoreUtils.DEFAULT_DATABASE_NAME, dropTbl.getTableName());
if (tbl != null)
work.getOutputs().add(new WriteEntity(tbl));
} else {
// get all partitions of the table
List<String> partitionNames = db.getPartitionNames(MetaStoreUtils.DEFAULT_DATABASE_NAME, dropTbl.getTableName(), (short)-1);
Set<Map<String, String>> partitions = new HashSet<Map<String, String>>();
for (int i = 0; i < partitionNames.size(); i++) {
try {
partitions.add(Warehouse.makeSpecFromName(partitionNames.get(i)));
} catch (MetaException e) {
LOG.warn("Unrecognized partition name from metastore: " + partitionNames.get(i));
}
}
// drop partitions in the list
List<Partition> partsToDelete = new ArrayList<Partition>();
for (Map<String, String> partSpec : dropTbl.getPartSpecs()) {
Iterator<Map<String,String>> it = partitions.iterator();
while (it.hasNext()) {
Map<String, String> part = it.next();
// test if partSpec matches part
boolean match = true;
for (Map.Entry<String, String> item: partSpec.entrySet()) {
if (!item.getValue().equals(part.get(item.getKey()))) {
match = false;
break;
}
}
if (match) {
partsToDelete.add(db.getPartition(tbl, part, false));
it.remove();
}
}
}
// drop all existing partitions from the list
for (Partition partition : partsToDelete) {
console.printInfo("Dropping the partition " + partition.getName());
db.dropPartition(MetaStoreUtils.DEFAULT_DATABASE_NAME, dropTbl
.getTableName(), partition.getValues(), true); // drop data for the
// partition
work.getOutputs().add(new WriteEntity(partition));
}
}
return 0;
}