morningman commented on code in PR #14793: URL: https://github.com/apache/doris/pull/14793#discussion_r1039076375
########## fe/fe-core/src/main/java/org/apache/doris/catalog/Env.java: ########## @@ -4443,8 +4443,16 @@ public void changeCatalog(ConnectContext ctx, String catalogName) throws DdlExce throw new DdlException(ErrorCode.ERR_UNKNOWN_CATALOG.formatErrorMsg(catalogName), ErrorCode.ERR_UNKNOWN_CATALOG); } + + String currentDB = ctx.getDatabase(); + if (StringUtils.isNotEmpty(currentDB)) { + catalogMgr.addLastDBOfCatalog(ctx.getCurrentCatalog().getName(), currentDB); + } ctx.changeDefaultCatalog(catalogName); - if (catalogIf instanceof EsExternalCatalog) { + String lastDb = catalogMgr.getLastDB(catalogName); + if (StringUtils.isNotEmpty(lastDb)) { + ctx.setDatabase(lastDb); + } else if (catalogIf instanceof EsExternalCatalog) { Review Comment: ```suggestion } if (catalogIf instanceof EsExternalCatalog) { ``` -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For queries about this service, please contact Infrastructure at: us...@infra.apache.org --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org