in metacat-main/src/main/java/com/netflix/metacat/main/services/impl/TableServiceImpl.java [558:632]
public void rename(
final QualifiedName oldName,
final QualifiedName newName,
final boolean isMView
) {
validate(oldName);
final MetacatRequestContext metacatRequestContext = MetacatContextManager.getContext();
this.authorizationService.checkPermission(metacatRequestContext.getUserName(),
oldName, MetacatOperation.RENAME);
final TableDto oldTable = get(oldName, GetTableServiceParameters.builder()
.includeInfo(true)
.disableOnReadMetadataIntercetor(false)
.includeDefinitionMetadata(true)
.includeDataMetadata(true)
.build()).orElseThrow(() -> new TableNotFoundException(oldName));
// Fail if the table is tagged not to be renamed.
if (hasTags(oldTable, config.getNoTableRenameOnTags())) {
if (MetacatUtils.hasDoNotModifyForIcebergMigrationTag(oldTable, config.getNoTableRenameOnTags())) {
throw new TableMigrationInProgressException(
MetacatUtils.getIcebergMigrationExceptionMsg("Rename", oldName.toString()));
} else {
throw new IllegalArgumentException(
String.format("Table %s cannot be renamed because it is tagged with %s.", oldName,
config.getNoTableRenameOnTags()));
}
}
if (oldTable != null) {
//Ignore if the operation is not supported, so that we can at least go ahead and save the user metadata
eventBus.post(new MetacatRenameTablePreEvent(oldName, metacatRequestContext, this, newName));
if (!config.isParentChildRenameEnabled()) {
if (parentChildRelMetadataService.isChildTable(oldName)) {
throw new RuntimeException(oldName + " is a child table and "
+ "renaming on child table is currently disabled");
}
if (parentChildRelMetadataService.isParentTable(oldName)) {
throw new RuntimeException(oldName + " is a parent table and "
+ "renaming on parent table is currently disabled");
}
}
// Before rename, first rename its parent child relation
parentChildRelMetadataService.rename(oldName, newName);
try {
connectorTableServiceProxy.rename(oldName, newName, isMView);
} catch (Exception e) {
try {
// if rename operation fail, rename back the parent child relation
parentChildRelMetadataService.rename(newName, oldName);
} catch (Exception renameException) {
log.error("parentChildRelMetadataService: Failed to rename parent child relation "
+ "after table fail to rename from {} to {} "
+ "with the following parameters oldName={} to newName={}",
oldName, newName, oldName, newName, renameException);
}
throw e;
}
userMetadataService.renameDefinitionMetadataKey(oldName, newName);
tagService.renameTableTags(oldName, newName.getTableName());
final TableDto dto = get(newName, GetTableServiceParameters.builder()
.includeInfo(true)
.disableOnReadMetadataIntercetor(false)
.includeDefinitionMetadata(true)
.includeDataMetadata(true)
.build()).orElseThrow(() -> new IllegalStateException("should exist"));
eventBus.post(
new MetacatRenameTablePostEvent(oldName, metacatRequestContext, this, oldTable, dto, isMView));
}
}