This is an automated email from the ASF dual-hosted git repository.

kxiao pushed a commit to branch branch-2.0
in repository https://gitbox.apache.org/repos/asf/doris.git

commit 68b54dde2e2f73e5e93d60a7341ae56adcfd3f6f
Author: Jibing-Li <[email protected]>
AuthorDate: Mon Jul 17 15:28:54 2023 +0800

    [Fix](statistics) Fix analyze db always use internal catalog bug (#21850)
    
    `Analyze database db_name ` command couldn't use current catalog, it is 
always using the internal catalog. This will cause the command failed to find 
the db. This pr is to fix this bug.
---
 .../org/apache/doris/analysis/AnalyzeDBStmt.java   |  2 +-
 .../hive/test_hive_analyze_db.out                  | 20 +++++++++++
 .../hive/test_hive_analyze_db.groovy               | 40 ++++++++++++++++++++++
 3 files changed, 61 insertions(+), 1 deletion(-)

diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeDBStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeDBStmt.java
index db155f07ae..4957bd2cb8 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeDBStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/AnalyzeDBStmt.java
@@ -44,7 +44,7 @@ public class AnalyzeDBStmt extends AnalyzeStmt {
     @Override
     public void analyze(Analyzer analyzer) throws AnalysisException, 
UserException {
         if (ctlName == null) {
-            ctlIf = Env.getCurrentInternalCatalog();
+            ctlIf = Env.getCurrentEnv().getCurrentCatalog();
         } else {
             ctlIf = 
Env.getCurrentEnv().getCatalogMgr().getCatalogOrAnalysisException(ctlName);
         }
diff --git 
a/regression-test/data/external_table_emr_p2/hive/test_hive_analyze_db.out 
b/regression-test/data/external_table_emr_p2/hive/test_hive_analyze_db.out
new file mode 100644
index 0000000000..0b75316476
--- /dev/null
+++ b/regression-test/data/external_table_emr_p2/hive/test_hive_analyze_db.out
@@ -0,0 +1,20 @@
+-- This file is automatically generated. You should know what you did if you 
want to edit this
+-- !1 --
+lo_orderpriority       100.0   5.0     0.0     888.8000000000001       8.8     
'1-URGENT'      '5-LOW'
+lo_custkey     100.0   26.0    0.0     404.0   4.0     67423   2735521
+lo_partkey     100.0   100.0   0.0     404.0   4.0     2250    989601
+lo_revenue     100.0   100.0   0.0     404.0   4.0     101171  8703450
+lo_commitdate  100.0   95.0    0.0     404.0   4.0     19920515        19981016
+lo_quantity    100.0   46.0    0.0     404.0   4.0     1       50
+lo_orderkey    100.0   26.0    0.0     404.0   4.0     1       98
+lo_suppkey     100.0   100.0   0.0     404.0   4.0     4167    195845
+lo_supplycost  100.0   100.0   0.0     404.0   4.0     58023   121374
+lo_shipmode    100.0   7.0     0.0     425.21  4.21    'AIR'   'TRUCK'
+lo_orderdate   100.0   26.0    0.0     404.0   4.0     19920221        19980721
+lo_linenumber  100.0   7.0     0.0     404.0   4.0     1       7
+lo_shippriority        100.0   1.0     0.0     404.0   4.0     0       0
+lo_ordtotalprice       100.0   26.0    0.0     404.0   4.0     3428256 36771805
+lo_extendedprice       100.0   100.0   0.0     404.0   4.0     104300  9066094
+lo_tax 100.0   9.0     0.0     404.0   4.0     0       8
+lo_discount    100.0   11.0    0.0     404.0   4.0     0       10
+
diff --git 
a/regression-test/suites/external_table_emr_p2/hive/test_hive_analyze_db.groovy 
b/regression-test/suites/external_table_emr_p2/hive/test_hive_analyze_db.groovy
new file mode 100644
index 0000000000..a30c87275b
--- /dev/null
+++ 
b/regression-test/suites/external_table_emr_p2/hive/test_hive_analyze_db.groovy
@@ -0,0 +1,40 @@
+// 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_hive_analyze_db", "p2") {
+    String enabled = context.config.otherConfigs.get("enableExternalHiveTest")
+    if (enabled != null && enabled.equalsIgnoreCase("true")) {
+        String extHiveHmsHost = 
context.config.otherConfigs.get("extHiveHmsHost")
+        String extHiveHmsPort = 
context.config.otherConfigs.get("extHiveHmsPort")
+        String catalog_name = "test_hive_analyze_db"
+        sql """drop catalog if exists ${catalog_name};"""
+        sql """
+            create catalog if not exists ${catalog_name} properties (
+                'type'='hms',
+                'hadoop.username' = 'hadoop',
+                'hive.metastore.uris' = 
'thrift://${extHiveHmsHost}:${extHiveHmsPort}'
+            );
+        """
+        logger.info("catalog " + catalog_name + " created")
+        sql """switch ${catalog_name};"""
+        logger.info("switched to catalog " + catalog_name)
+        sql """use statistics;"""
+        sql """analyze database statistics with sync"""
+        qt_1 "show column stats statistics"
+    }
+}
+


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to