From 9c900cb6d2bfe5d0a2c4d0e6cdfeb7a3caecf6f8 Mon Sep 17 00:00:00 2001 From: GoGoWen <82132356+GoGoWen@users.noreply.github.com> Date: Mon, 10 Apr 2023 14:13:12 +0800 Subject: [PATCH] [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. --- .../apache/doris/datasource/CatalogMgr.java | 2 +- .../org/apache/doris/qe/ShowExecutor.java | 6 ++-- .../query_p0/show/test_show_catalogs.groovy | 33 +++++++++++++++++++ 3 files changed, 36 insertions(+), 5 deletions(-) create mode 100644 regression-test/suites/query_p0/show/test_show_catalogs.groovy diff --git a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java index 1d219da65f..9d8c3fe985 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java +++ b/fe/fe-core/src/main/java/org/apache/doris/datasource/CatalogMgr.java @@ -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(""); diff --git a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java index aadc9129a0..709bea5b31 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/qe/ShowExecutor.java @@ -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 diff --git a/regression-test/suites/query_p0/show/test_show_catalogs.groovy b/regression-test/suites/query_p0/show/test_show_catalogs.groovy new file mode 100644 index 0000000000..85be7d0975 --- /dev/null +++ b/regression-test/suites/query_p0/show/test_show_catalogs.groovy @@ -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;""" +}