Table table, FileSystem fs,
String grpName, FsPermission perms) throws IOException {
StorageDescriptor tblSD = table.getSd();
Partition partition = new Partition();
partition.setDbName(table.getDbName());
partition.setTableName(table.getTableName());
partition.setSd(new StorageDescriptor(tblSD));
List<FieldSchema> fields = new ArrayList<FieldSchema>();
for(HCatFieldSchema fieldSchema : outputSchema.getFields()) {
fields.add(HCatSchemaUtils.getFieldSchema(fieldSchema));
}
partition.getSd().setCols(fields);
partition.setValues(getPartitionValueList(table,partKVs));
partition.setParameters(params);
// Sets permissions and group name on partition dirs.
Path partPath = new Path(partLocnRoot);
for(FieldSchema partKey : table.getPartitionKeys()){
partPath = constructPartialPartPath(partPath, partKey.getName().toLowerCase(), partKVs);
// LOG.info("Setting perms for "+partPath.toString());
fs.setPermission(partPath, perms);
try{
fs.setOwner(partPath, null, grpName);
} catch(AccessControlException ace){
// log the messages before ignoring. Currently, logging is not built in Hcatalog.
// LOG.warn(ace);
}
}
if (dynamicPartitioningUsed){
String dynamicPartitionDestination = getFinalDynamicPartitionDestination(table,partKVs);
if (harProcessor.isEnabled()){
harProcessor.exec(context, partition, partPath);
partition.getSd().setLocation(
harProcessor.getProcessedLocation(new Path(dynamicPartitionDestination)));
}else{
partition.getSd().setLocation(dynamicPartitionDestination);
}
}else{
partition.getSd().setLocation(partPath.toString());
}
return partition;
}