@Override
public void alterTableDefinitions(Session session, Collection<ChangedTableDescription> alteredTables) {
ArgumentValidation.notEmpty("alteredTables", alteredTables);
AkibanInformationSchema oldAIS = getAISForChange(session);
Set<String> schemas = new HashSet<>();
List<Integer> tableIDs = new ArrayList<>(alteredTables.size());
for(ChangedTableDescription desc : alteredTables) {
TableName oldName = desc.getOldName();
TableName newName = desc.getNewName();
checkTableName(session, oldName, true, false);
if(!oldName.equals(newName)) {
checkTableName(session, newName, false, false);
}
Table newTable = desc.getNewDefinition();
if(newTable != null) {
AISInvariants.checkJoinTo(newTable.getParentJoin(), newName, false);
if(newTable.getColumns().isEmpty()) {
throw new NoColumnsInTableException(newName);
}
}
schemas.add(oldName.getSchemaName());
schemas.add(newName.getSchemaName());
tableIDs.add(oldAIS.getTable(oldName).getTableId());
}
AISMerge merge = AISMerge.newForModifyTable(aisCloner, getNameGenerator(session), oldAIS, alteredTables);
merge.merge();
final AkibanInformationSchema newAIS = merge.getAIS();
for(ChangedTableDescription desc : alteredTables) {
Table newTable = newAIS.getTable(desc.getNewName());
ensureUuids(newTable);
// New groups require new ordinals
if(desc.isNewGroup()) {
newTable.setOrdinal(null);
}
}
// Two passes to ensure all tables in a group are reset before beginning assignment
for(ChangedTableDescription desc : alteredTables) {
if(desc.isNewGroup()) {
Table newTable = newAIS.getTable(desc.getOldName());
assignNewOrdinal(newTable);
}
}
saveAISChange(session, newAIS, schemas, tableIDs);