in aws-glue-datacatalog-client-common/src/main/java/com/amazonaws/glue/catalog/metastore/GlueMetastoreClientDelegate.java [409:457]
public void alterTable(
String dbName,
String oldTableName,
org.apache.hadoop.hive.metastore.api.Table newTable,
EnvironmentContext environmentContext
) throws TException {
checkArgument(StringUtils.isNotEmpty(dbName), "dbName cannot be null or empty");
checkArgument(StringUtils.isNotEmpty(oldTableName), "oldTableName cannot be null or empty");
checkNotNull(newTable, "newTable cannot be null");
if (isCascade(environmentContext)) {
throw new UnsupportedOperationException("Cascade for alter_table is not supported");
}
if (!oldTableName.equals(newTable.getTableName())) {
throw new UnsupportedOperationException("Table rename is not supported");
}
validateTableObject(newTable, conf);
if (!tableExists(dbName, oldTableName)) {
throw new UnknownTableException("Table: " + oldTableName + " does not exists");
}
// If table properties has EXTERNAL set, update table type accordinly
// mimics Hive's ObjectStore#convertToMTable, added in HIVE-1329
boolean isExternal = Boolean.parseBoolean(newTable.getParameters().get("EXTERNAL"));
if (MANAGED_TABLE.toString().equals(newTable.getTableType()) && isExternal) {
newTable.setTableType(EXTERNAL_TABLE.toString());
} else if (EXTERNAL_TABLE.toString().equals(newTable.getTableType()) && !isExternal) {
newTable.setTableType(MANAGED_TABLE.toString());
}
if (hiveShims.requireCalStats(conf, null, null, newTable, environmentContext) && newTable.getPartitionKeys().isEmpty()) {
//update table stats for non-partition Table
org.apache.hadoop.hive.metastore.api.Database db = getDatabase(newTable.getDbName());
hiveShims.updateTableStatsFast(db, newTable, wh, false, true, environmentContext);
}
try {
TableInput newTableInput = GlueInputConverter.convertToTableInput(newTable);
glueMetastore.updateTable(dbName, newTableInput);
} catch (AmazonServiceException e) {
throw CatalogToHiveConverter.wrapInHiveException(e);
} catch (Exception e) {
String msg = "Unable to alter table: " + oldTableName;
logger.error(msg, e);
throw new MetaException(msg + e);
}
}