if (resolved.equals(namespace)) {
// the requested dataset already exists
throw new DatasetExistsException(
"Metadata already exists for dataset: " + namespace + "." + name);
} else {
DatasetDescriptor loaded = load(resolved, name);
// replacing old default.name table
LOG.warn("Creating table managed table {}.{}: replaces default.{}",
new Object[]{namespace, name, name});
// validate that the new metadata can read the existing data
Compatibility.checkUpdate(loaded, descriptor);
// if the table in the default namespace matches, then the location is
// either null (and should be set to the existing) or matches. either
// way, use the loaded location.
location = loaded.getLocation();
}
}
LOG.info("Creating a managed Hive table named: " + name);
boolean isExternal = (location != null);
DatasetDescriptor toCreate = descriptor;
if (isExternal) {
// add the location to the descriptor that will be used
toCreate = new DatasetDescriptor.Builder(descriptor)
.location(location)
.build();
}
// construct the table metadata from a descriptor
Table table = HiveUtils.tableForDescriptor(
namespace, name, toCreate, isExternal);
// create it
getMetaStoreUtil().createTable(table);
// load the created table to get the final data location
Table newTable = getMetaStoreUtil().getTable(namespace, name);
DatasetDescriptor newDescriptor = new DatasetDescriptor.Builder(descriptor)
.location(newTable.getSd().getLocation())
.build();
if (isExternal) {
FileSystemUtil.ensureLocationExists(newDescriptor, conf);