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

morningman pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/doris.git


The following commit(s) were added to refs/heads/master by this push:
     new 9805092ffdd [Fix](Export) `show export` statement supports specify the 
catalog name (#41662)
9805092ffdd is described below

commit 9805092ffdd5e34960b783724f1e96a22a024c3e
Author: Tiewei Fang <[email protected]>
AuthorDate: Sun Oct 13 20:17:25 2024 +0800

    [Fix](Export) `show export` statement supports specify the catalog name 
(#41662)
---
 fe/fe-core/src/main/cup/sql_parser.cup             |  4 ++++
 .../org/apache/doris/analysis/ShowExportStmt.java  | 28 +++++++++++++++++++++-
 .../java/org/apache/doris/qe/ShowExecutor.java     |  4 +++-
 .../apache/doris/analysis/ShowExportStmtTest.java  | 10 ++++----
 .../export/test_export_external_table.groovy       | 21 +++++++---------
 5 files changed, 48 insertions(+), 19 deletions(-)

diff --git a/fe/fe-core/src/main/cup/sql_parser.cup 
b/fe/fe-core/src/main/cup/sql_parser.cup
index 0ffcaf0c488..0cfd889f0a8 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -4469,6 +4469,10 @@ show_param ::=
     {:
         RESULT = new ShowExportStmt(db, parser.where, orderByClause, 
limitClause);
     :}
+    | KW_EXPORT from_or_in ident:ctl DOT ident:db opt_wild_where 
order_by_clause:orderByClause limit_clause:limitClause
+    {:
+        RESULT = new ShowExportStmt(ctl, db, parser.where, orderByClause, 
limitClause);
+    :}
     /* Show delete statement */
     | KW_DELETE opt_db:db
     {:
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowExportStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowExportStmt.java
index 757eaf83bac..1e929911e06 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowExportStmt.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowExportStmt.java
@@ -43,6 +43,7 @@ import java.util.List;
 public class ShowExportStmt extends ShowStmt implements NotFallbackInParser {
     private static final Logger LOG = 
LogManager.getLogger(ShowExportStmt.class);
 
+    private String ctlName;
     private String dbName;
     private final Expr whereClause;
     private final LimitElement limitElement;
@@ -64,6 +65,19 @@ public class ShowExportStmt extends ShowStmt implements 
NotFallbackInParser {
         this.limitElement = limitElement;
     }
 
+    public ShowExportStmt(String ctl, String db, Expr whereExpr, 
List<OrderByElement> orderByElements,
+            LimitElement limitElement) {
+        this.ctlName = ctl;
+        this.dbName = db;
+        this.whereClause = whereExpr;
+        this.orderByElements = orderByElements;
+        this.limitElement = limitElement;
+    }
+
+    public String getCtlName() {
+        return ctlName;
+    }
+
     public String getDbName() {
         return dbName;
     }
@@ -101,6 +115,13 @@ public class ShowExportStmt extends ShowStmt implements 
NotFallbackInParser {
     @Override
     public void analyze(Analyzer analyzer) throws AnalysisException, 
UserException {
         super.analyze(analyzer);
+        if (Strings.isNullOrEmpty(ctlName)) {
+            ctlName = analyzer.getDefaultCatalog();
+            if (Strings.isNullOrEmpty(ctlName)) {
+                
ErrorReport.reportAnalysisException(ErrorCode.ERR_UNKNOWN_CATALOG);
+            }
+        }
+
         if (Strings.isNullOrEmpty(dbName)) {
             dbName = analyzer.getDefaultDb();
             if (Strings.isNullOrEmpty(dbName)) {
@@ -183,7 +204,12 @@ public class ShowExportStmt extends ShowStmt implements 
NotFallbackInParser {
         StringBuilder sb = new StringBuilder();
         sb.append("SHOW EXPORT ");
         if (!Strings.isNullOrEmpty(dbName)) {
-            sb.append("FROM `").append(dbName).append("`");
+            if (!Strings.isNullOrEmpty(ctlName)) {
+                sb.append("FROM `").append(ctlName).append("`.`");
+            } else {
+                sb.append("FROM `");
+            }
+            sb.append(dbName).append("`");
         }
 
         if (whereClause != null) {
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 8204f00676d..153823c2edc 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
@@ -2231,7 +2231,9 @@ public class ShowExecutor {
     private void handleShowExport() throws AnalysisException {
         ShowExportStmt showExportStmt = (ShowExportStmt) stmt;
         Env env = Env.getCurrentEnv();
-        DatabaseIf db = 
env.getCurrentCatalog().getDbOrAnalysisException(showExportStmt.getDbName());
+        CatalogIf catalog = env.getCatalogMgr()
+                .getCatalogOrAnalysisException(showExportStmt.getCtlName());
+        DatabaseIf db = 
catalog.getDbOrAnalysisException(showExportStmt.getDbName());
         long dbId = db.getId();
 
         ExportMgr exportMgr = env.getExportMgr();
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowExportStmtTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowExportStmtTest.java
index ed8c33fb9e4..bed2f3c7362 100644
--- a/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowExportStmtTest.java
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowExportStmtTest.java
@@ -38,14 +38,14 @@ public class ShowExportStmtTest {
     public void testNormal() throws UserException {
         ShowExportStmt stmt = new ShowExportStmt(null, null, null, null);
         stmt.analyze(analyzer);
-        Assert.assertEquals("SHOW EXPORT FROM `testDb`", stmt.toString());
+        Assert.assertEquals("SHOW EXPORT FROM `internal`.`testDb`", 
stmt.toString());
     }
 
     @Test
     public void testWhere() throws UserException {
         ShowExportStmt stmt = new ShowExportStmt(null, null, null, null);
         stmt.analyze(analyzer);
-        Assert.assertEquals("SHOW EXPORT FROM `testDb`", stmt.toString());
+        Assert.assertEquals("SHOW EXPORT FROM `internal`.`testDb`", 
stmt.toString());
 
         SlotRef slotRef = new SlotRef(null, "label");
         StringLiteral stringLiteral = new StringLiteral("abc");
@@ -53,7 +53,7 @@ public class ShowExportStmtTest {
 
         stmt = new ShowExportStmt(null, binaryPredicate, null, new 
LimitElement(10));
         stmt.analyze(analyzer);
-        Assert.assertEquals("SHOW EXPORT FROM `testDb` WHERE (`label` = 'abc') 
LIMIT 10", stmt.toString());
+        Assert.assertEquals("SHOW EXPORT FROM `internal`.`testDb` WHERE 
(`label` = 'abc') LIMIT 10", stmt.toString());
         Assert.assertFalse(stmt.isLabelUseLike());
 
         StringLiteral stringLiteralLike = new StringLiteral("ab%");
@@ -61,13 +61,13 @@ public class ShowExportStmtTest {
 
         stmt = new ShowExportStmt(null, likePredicate, null, new 
LimitElement(10));
         stmt.analyze(analyzer);
-        Assert.assertEquals("SHOW EXPORT FROM `testDb` WHERE `label` LIKE 
'ab%' LIMIT 10", stmt.toString());
+        Assert.assertEquals("SHOW EXPORT FROM `internal`.`testDb` WHERE 
`label` LIKE 'ab%' LIMIT 10", stmt.toString());
         Assert.assertTrue(stmt.isLabelUseLike());
 
         BinaryPredicate statePredicate = new BinaryPredicate(Operator.EQ, new 
SlotRef(null, "state"), new StringLiteral("PENDING"));
         stmt = new ShowExportStmt(null, statePredicate, null, new 
LimitElement(10));
         stmt.analyze(analyzer);
-        Assert.assertEquals("SHOW EXPORT FROM `testDb` WHERE (`state` = 
'PENDING') LIMIT 10", stmt.toString());
+        Assert.assertEquals("SHOW EXPORT FROM `internal`.`testDb` WHERE 
(`state` = 'PENDING') LIMIT 10", stmt.toString());
     }
 
     @Test
diff --git 
a/regression-test/suites/external_table_p0/export/test_export_external_table.groovy
 
b/regression-test/suites/external_table_p0/export/test_export_external_table.groovy
index 4ccb5bbca2e..8125db28bf1 100644
--- 
a/regression-test/suites/external_table_p0/export/test_export_external_table.groovy
+++ 
b/regression-test/suites/external_table_p0/export/test_export_external_table.groovy
@@ -86,9 +86,9 @@ suite("test_export_external_table", 
"p0,external,mysql,external_docker,external_
             path.delete();
         }
     }
-    def waiting_export = { export_label ->
+    def waiting_export = { ctlName, dbName, export_label ->
         while (true) {
-            def res = sql """ show export where label = "${export_label}" """
+            def res = sql """ show export from ${ctlName}.${dbName} where 
label = "${export_label}" """
             logger.info("export state: " + res[0][2])
             if (res[0][2] == "FINISHED") {
                 break;
@@ -179,7 +179,7 @@ suite("test_export_external_table", 
"p0,external,mysql,external_docker,external_
                     "column_separator"=","
                 );
             """
-            waiting_export.call(label)
+            waiting_export.call(catalog_name, ex_db_name, label)
             
             // check file amounts
             check_file_amounts.call("${outFilePath}", 1)
@@ -236,10 +236,7 @@ suite("test_export_external_table", 
"p0,external,mysql,external_docker,external_
                 );
             """
 
-            sql """ switch ${catalog_name} """
-            sql """ use ${ex_db_name} """
-
-            waiting_export.call(label)
+            waiting_export.call(catalog_name, ex_db_name, label)
             
             // check file amounts
             check_file_amounts.call("${outFilePath}", 1)
@@ -295,7 +292,7 @@ suite("test_export_external_table", 
"p0,external,mysql,external_docker,external_
                     "column_separator"=","
                 );
             """
-            waiting_export.call(label)
+            waiting_export.call(catalog_name, ex_db_name, label)
             
             // check file amounts
             check_file_amounts.call("${outFilePath}", 1)
@@ -352,7 +349,7 @@ suite("test_export_external_table", 
"p0,external,mysql,external_docker,external_
                     "column_separator"=","
                 );
             """
-            waiting_export.call(label)
+            waiting_export.call(catalog_name, ex_db_name, label)
             
             // check file amounts
             check_file_amounts.call("${outFilePath}", 1)
@@ -408,7 +405,7 @@ suite("test_export_external_table", 
"p0,external,mysql,external_docker,external_
                     "format" = "orc"
                 );
             """
-            waiting_export.call(label)
+            waiting_export.call(catalog_name, ex_db_name, label)
             
             // check file amounts
             check_file_amounts.call("${outFilePath}", 1)
@@ -463,7 +460,7 @@ suite("test_export_external_table", 
"p0,external,mysql,external_docker,external_
                     "format" = "parquet"
                 );
             """
-            waiting_export.call(label)
+            waiting_export.call(catalog_name, ex_db_name, label)
             
             // check file amounts
             check_file_amounts.call("${outFilePath}", 1)
@@ -520,7 +517,7 @@ suite("test_export_external_table", 
"p0,external,mysql,external_docker,external_
                     "column_separator"=","
                 );
             """
-            waiting_export.call(label)
+            waiting_export.call(catalog_name, ex_db_name, label)
             
             // check file amounts
             check_file_amounts.call("${outFilePath}", 1)


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

Reply via email to