This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch branch-1.2-lts in repository https://gitbox.apache.org/repos/asf/doris.git
commit 049c1f09803906ac4cd67d1d8bb463d48f63dadc Author: xueweizhang <zxw520bl...@163.com> AuthorDate: Sat Dec 24 15:20:00 2022 +0800 [feature](multi-catalog) support use catalog.db when client connect to the doris server (#15293) --- .../java/org/apache/doris/mysql/MysqlProto.java | 31 +++++++++++++++++++++- 1 file changed, 30 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java b/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java index ff2b757892..9dd346ce6e 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java +++ b/fe/fe-core/src/main/java/org/apache/doris/mysql/MysqlProto.java @@ -26,6 +26,7 @@ import org.apache.doris.common.DdlException; import org.apache.doris.common.ErrorCode; import org.apache.doris.common.ErrorReport; import org.apache.doris.common.LdapConfig; +import org.apache.doris.datasource.CatalogIf; import org.apache.doris.ldap.LdapAuthenticate; import org.apache.doris.mysql.privilege.PaloAuth; import org.apache.doris.mysql.privilege.UserResource; @@ -276,8 +277,36 @@ public class MysqlProto { // set database String db = authPacket.getDb(); if (!Strings.isNullOrEmpty(db)) { + String catalogName = null; + String dbName = null; + String[] dbNames = db.split("\\."); + if (dbNames.length == 1) { + dbName = db; + } else if (dbNames.length == 2) { + catalogName = dbNames[0]; + dbName = dbNames[1]; + } else if (dbNames.length > 2) { + context.getState().setError(ErrorCode.ERR_BAD_DB_ERROR, "Only one dot can be in the name: " + db); + return false; + } + String dbFullName = ClusterNamespace.getFullName(context.getClusterName(), dbName); + + // check catalog and db exists + if (catalogName != null) { + CatalogIf catalogIf = context.getEnv().getCatalogMgr().getCatalogNullable(catalogName); + if (catalogIf == null) { + context.getState().setError(ErrorCode.ERR_BAD_DB_ERROR, "No match catalog in doris: " + db); + return false; + } + if (catalogIf.getDbNullable(dbName) == null) { + context.getState().setError(ErrorCode.ERR_BAD_DB_ERROR, "No match database in doris: " + db); + return false; + } + } try { - String dbFullName = ClusterNamespace.getFullName(context.getClusterName(), db); + if (catalogName != null) { + context.getEnv().changeCatalog(context, catalogName); + } Env.getCurrentEnv().changeDb(context, dbFullName); } catch (DdlException e) { context.getState().setError(e.getMysqlErrorCode(), e.getMessage()); --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org