Skip to content

Commit

Permalink
[fix](multi-catalog) check new catalog name is used or not before ren…
Browse files Browse the repository at this point in the history
…ame (#14891)
  • Loading branch information
Yulei-Yang authored and morningman committed Dec 14, 2022
1 parent 8c507ac commit 15561cf
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,9 @@ public void alterCatalogName(AlterCatalogNameStmt stmt) throws UserException {
if (catalog == null) {
throw new DdlException("No catalog found with name: " + stmt.getCatalogName());
}
if (nameToCatalog.get(stmt.getNewCatalogName()) != null) {
throw new DdlException("Catalog with name " + stmt.getNewCatalogName() + " already exist");
}
CatalogLog log = CatalogFactory.constructorCatalogLog(catalog.getId(), stmt);
replayAlterCatalogName(log);
Env.getCurrentEnv().getEditLog().logCatalogLog(OperationType.OP_ALTER_CATALOG_NAME, log);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.apache.doris.catalog.external.HMSExternalTable;
import org.apache.doris.common.AnalysisException;
import org.apache.doris.common.Config;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.FeConstants;
import org.apache.doris.mysql.privilege.PaloAuth;
import org.apache.doris.qe.ConnectContext;
Expand Down Expand Up @@ -167,6 +168,17 @@ public void testNormalCase() throws Exception {
showResultSet = mgr.showCatalogs(showStmt);
Assertions.assertEquals(1, showResultSet.getResultRows().size());

String alterCatalogNameFailSql = "ALTER CATALOG hms_catalog RENAME hive;";
AlterCatalogNameStmt alterNameFailStmt = (AlterCatalogNameStmt) parseAndAnalyzeStmt(alterCatalogNameFailSql);

try {
mgr.alterCatalogName(alterNameFailStmt);
Assert.fail("Catalog with name hive already exist, rename should be failed");
} catch (DdlException e) {
Assert.assertEquals(e.getMessage(),
"errCode = 2, detailMessage = Catalog with name hive already exist");
}

String alterCatalogNameSql = "ALTER CATALOG hms_catalog RENAME " + MY_CATALOG + ";";
AlterCatalogNameStmt alterNameStmt = (AlterCatalogNameStmt) parseAndAnalyzeStmt(alterCatalogNameSql);
mgr.alterCatalogName(alterNameStmt);
Expand Down

0 comments on commit 15561cf

Please sign in to comment.