You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@doris.apache.org by mo...@apache.org on 2023/04/11 15:48:33 UTC

[doris] 01/02: [fix](multi catalog) fix show catalogs after drop (#18481)

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 4157c7d939e1b35db8f1188ee1481476a9aed288
Author: GoGoWen <82...@users.noreply.github.com>
AuthorDate: Mon Apr 10 14:13:12 2023 +0800

    [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.
---
 .../org/apache/doris/datasource/CatalogMgr.java    |  2 +-
 .../java/org/apache/doris/qe/ShowExecutor.java     |  6 ++--
 .../suites/query_p0/show/test_show_catalogs.groovy | 33 ++++++++++++++++++++++
 3 files changed, 36 insertions(+), 5 deletions(-)

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 65f88d428f..41732927fc 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
@@ -366,7 +366,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 a6bd0ee5ef..b3969b7b30 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
@@ -2326,10 +2326,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;"""
+}


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@doris.apache.org
For additional commands, e-mail: commits-help@doris.apache.org