[fix](multi catalog) fix show catalogs after drop (#18481)

steps to repo:
1, create any catalog re; [OK]
2, switch re [OK]
3, show catalogs [OK]
4, drop catalog re [OK]
5, show catalogs [FAIL with "Current catalog is not exist, please switch catalog." ]

expect:
show catalogs should always be OK, not depends on current catalog.
This commit is contained in:
GoGoWen
2023-04-10 14:13:12 +08:00
committed by GitHub
parent a8315b86ca
commit 9c900cb6d2
3 changed files with 36 additions and 5 deletions

View File

@ -368,7 +368,7 @@ public class CatalogMgr implements Writable, GsonPostProcessable {
row.add(String.valueOf(catalog.getId()));
row.add(name);
row.add(catalog.getType());
if (name.equals(currentCtlg)) {
if (currentCtlg != null && name.equals(currentCtlg)) {
row.add(YES);
} else {
row.add("");

View File

@ -2434,10 +2434,8 @@ public class ShowExecutor {
public void handleShowCatalogs() throws AnalysisException {
ShowCatalogStmt showStmt = (ShowCatalogStmt) stmt;
if (ctx.getCurrentCatalog() == null) {
throw new AnalysisException("Current catalog is not exist, please switch catalog.");
}
resultSet = Env.getCurrentEnv().getCatalogMgr().showCatalogs(showStmt, ctx.getCurrentCatalog().getName());
resultSet = Env.getCurrentEnv().getCatalogMgr().showCatalogs(showStmt, ctx.getCurrentCatalog() != null
? ctx.getCurrentCatalog().getName() : null);
}
// Show create catalog

View File

@ -0,0 +1,33 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.
suite("test_show_catalogs") {
// define a catalog name
String catalog_name = "test_show_catalogs";
sql """drop catalog if exists ${catalog_name} """
sql """CREATE CATALOG ${catalog_name} PROPERTIES (
"hive.metastore.uris" = "thrift://11.119.172.189:9083",
"type" = "hms"
);"""
sql """switch ${catalog_name};"""
sql """drop catalog ${catalog_name};"""
//should be OK to call show catalogs after drop current catalog
sql """show catalogs;"""
}