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/incubator-doris.git


The following commit(s) were added to refs/heads/master by this push:
     new ba69f7a  [Command] [SQL] Add show database/table/partition id command 
(#5807)
ba69f7a is described below

commit ba69f7a7c80c843a2e6fbff4218e7b8dea681b60
Author: xinghuayu007 <[email protected]>
AuthorDate: Wed May 26 09:58:02 2021 +0800

    [Command] [SQL] Add show database/table/partition id command (#5807)
    
    In BE, when a problem happened, in the log, we can find the database id, 
table id, partition id,
    but no database name, table name, partition name.
    
    In FE, there also no way to find database name/table name/partition name 
accourding to
    database id/table id/partition id. Therefore, this patch add 3 new commands:
    
    1. show database id;
    mysql> show database 10002;
    +----------------------+
    | DbName               |
    +----------------------+
    | default_cluster:test |
    +----------------------+
    
    2. show table id;
    mysql> show table 11100;
    +----------------------+-----------+-------+
    | DbName               | TableName | DbId  |
    +----------------------+-----------+-------+
    | default_cluster:test | table2    | 10002 |
    +----------------------+-----------+-------+
    
    3. show partition id;
    mysql> show partition 11099;
    +----------------------+-----------+---------------+-------+---------+
    | DbName               | TableName | PartitionName | DbId  | TableId |
    +----------------------+-----------+---------------+-------+---------+
    | default_cluster:test | table2    | p201708       | 10002 | 11100   |
    +----------------------+-----------+---------------+-------+---------+
---
 .../Data Manipulation/SHOW DATABASE.md             | 38 ++++++++++
 .../Data Manipulation/SHOW PARTITION.md            | 38 ++++++++++
 .../sql-statements/Data Manipulation/SHOW TABLE.md | 38 ++++++++++
 .../Data Manipulation/SHOW DATABASE.md             | 39 ++++++++++
 .../Data Manipulation/SHOW PARTITION.md            | 39 ++++++++++
 .../sql-statements/Data Manipulation/SHOW TABLE.md | 39 ++++++++++
 fe/fe-core/src/main/cup/sql_parser.cup             | 15 ++++
 .../org/apache/doris/analysis/ShowDbIdStmt.java    | 70 ++++++++++++++++++
 .../apache/doris/analysis/ShowPartitionIdStmt.java | 74 +++++++++++++++++++
 .../org/apache/doris/analysis/ShowTableIdStmt.java | 73 +++++++++++++++++++
 .../java/org/apache/doris/qe/ShowExecutor.java     | 83 ++++++++++++++++++++++
 .../apache/doris/analysis/ShowDbIdStmtTest.java    | 53 ++++++++++++++
 .../doris/analysis/ShowPartitionIdStmtTest.java    | 58 +++++++++++++++
 .../apache/doris/analysis/ShowTableIdStmtTest.java | 51 +++++++++++++
 14 files changed, 708 insertions(+)

diff --git a/docs/en/sql-reference/sql-statements/Data Manipulation/SHOW 
DATABASE.md b/docs/en/sql-reference/sql-statements/Data Manipulation/SHOW 
DATABASE.md
new file mode 100644
index 0000000..cd4ed4d
--- /dev/null
+++ b/docs/en/sql-reference/sql-statements/Data Manipulation/SHOW DATABASE.md   
@@ -0,0 +1,38 @@
+---
+{
+    "title": "SHOW DATABASE",
+    "language": "en"
+}
+---
+
+<!-- 
+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.
+-->
+
+# SHOW DATABASE
+## Description
+This statement is used to display database name according to database id (for 
administrators only)
+Grammar:
+SHOW DATABASE [database_id]
+
+## example
+1. Display database name according to database id
+SHOW DATABASE 1001;
+
+## keyword
+SHOW,DATABASE
diff --git a/docs/en/sql-reference/sql-statements/Data Manipulation/SHOW 
PARTITION.md b/docs/en/sql-reference/sql-statements/Data Manipulation/SHOW 
PARTITION.md
new file mode 100644
index 0000000..6ccbac4
--- /dev/null
+++ b/docs/en/sql-reference/sql-statements/Data Manipulation/SHOW PARTITION.md  
@@ -0,0 +1,38 @@
+---
+{
+    "title": "SHOW PARTITION",
+    "language": "en"
+}
+---
+
+<!-- 
+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.
+-->
+
+# SHOW PARTITION
+## Description
+This statement is used to display database name, table name, partition name 
according to partition id (for administrators only)
+Grammar:
+SHOW PARTITION [partition_id]
+
+## example
+1. Display database name, table name, partition name according to partition id
+SHOW PARTITION 10002;
+
+## keyword
+SHOW,PARTITION
diff --git a/docs/en/sql-reference/sql-statements/Data Manipulation/SHOW 
TABLE.md b/docs/en/sql-reference/sql-statements/Data Manipulation/SHOW TABLE.md
new file mode 100644
index 0000000..dc4306b
--- /dev/null
+++ b/docs/en/sql-reference/sql-statements/Data Manipulation/SHOW TABLE.md      
@@ -0,0 +1,38 @@
+---
+{
+    "title": "SHOW TABLE",
+    "language": "en"
+}
+---
+
+<!-- 
+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.
+-->
+
+# SHOW TABLE
+## Description
+This statement is used to display database name, table name according to table 
id (for administrators only)
+Grammar:
+SHOW TABLE [table_id]
+
+## example
+1. Display database name, table name according to table id
+SHOW TABLE 10001;
+
+## keyword
+SHOW,TABLE
diff --git a/docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW 
DATABASE.md b/docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW 
DATABASE.md
new file mode 100644
index 0000000..aa8e43b
--- /dev/null
+++ b/docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW 
DATABASE.md        
@@ -0,0 +1,39 @@
+---
+{
+    "title": "SHOW DATABASE",
+    "language": "zh-CN"
+}
+---
+
+<!-- 
+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.
+-->
+
+# SHOW DATABASE
+## description
+    该语句用于根据 database id 查找对应的 database name(仅管理员使用)
+    语法:
+        SHOW DATABASE [database_id]
+
+## example
+    1. 根据 database id 查找对应的 database name
+        SHOW DATABASE 1001;
+
+## keyword
+    SHOW,DATABASE
+
diff --git a/docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW 
PARTITION.md b/docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW 
PARTITION.md
new file mode 100644
index 0000000..f41029b
--- /dev/null
+++ b/docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW 
PARTITION.md       
@@ -0,0 +1,39 @@
+---
+{
+    "title": "SHOW PARTITION",
+    "language": "zh-CN"
+}
+---
+
+<!-- 
+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.
+-->
+
+# SHOW DATABASE
+## description
+    该语句用于根据 partition id 查找对应的 database name, table name, partition 
name(仅管理员使用)
+    语法:
+        SHOW PARTITION [partition_id]
+
+## example
+    1. 根据 partition id 查找对应的 database name, table name, partition name
+        SHOW PARTITION 10002;
+
+## keyword
+    SHOW,PARTITION
+
diff --git a/docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW 
TABLE.md b/docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW 
TABLE.md
new file mode 100644
index 0000000..96a2ae9
--- /dev/null
+++ b/docs/zh-CN/sql-reference/sql-statements/Data Manipulation/SHOW TABLE.md   
@@ -0,0 +1,39 @@
+---
+{
+    "title": "SHOW TABLE",
+    "language": "zh-CN"
+}
+---
+
+<!-- 
+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.
+-->
+
+# SHOW DATABASE
+## description
+    该语句用于根据 table id 查找对应的 database name, table name(仅管理员使用)
+    语法:
+        SHOW TABLE [table_id]
+
+## example
+    1. 根据 table id 查找对应的 database name, table name
+        SHOW TABLE 10001;
+
+## keyword
+    SHOW,TABLE
+
diff --git a/fe/fe-core/src/main/cup/sql_parser.cup 
b/fe/fe-core/src/main/cup/sql_parser.cup
index 02aa5ed..c5c19f6 100644
--- a/fe/fe-core/src/main/cup/sql_parser.cup
+++ b/fe/fe-core/src/main/cup/sql_parser.cup
@@ -2306,6 +2306,11 @@ show_param ::=
     {:
         RESULT = new ShowTableStmt(db, parser.isVerbose, parser.wild, 
parser.where);
     :}
+    /* show table id */
+    | KW_TABLE INTEGER_LITERAL:tableId
+    {:
+        RESULT = new ShowTableIdStmt(tableId);
+    :}
     /* show processlist */
     | opt_full KW_PROCESSLIST
     {:
@@ -2383,6 +2388,11 @@ show_param ::=
     {:
         RESULT = new ShowDbStmt(parser.wild, parser.where);
     :}
+    /* show database id */
+    | KW_DATABASE INTEGER_LITERAL:dbId
+    {:
+        RESULT = new ShowDbIdStmt(dbId);
+    :}
     | KW_SCHEMAS opt_wild_where
     {:
         RESULT = new ShowDbStmt(parser.wild, parser.where);
@@ -2480,6 +2490,11 @@ show_param ::=
     {:
         RESULT = new ShowPartitionsStmt(tblName, parser.where, orderByClause, 
limitClause, tmp);
     :}
+    /* show partition id */
+    | KW_PARTITION INTEGER_LITERAL:partitionId
+    {:
+        RESULT = new ShowPartitionIdStmt(partitionId);
+    :}
     | KW_TABLET INTEGER_LITERAL:tabletId
     {:
         RESULT = new ShowTabletStmt(null, tabletId);
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDbIdStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDbIdStmt.java
new file mode 100644
index 0000000..d7eadff
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowDbIdStmt.java
@@ -0,0 +1,70 @@
+// 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.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.ShowResultSetMetaData;
+
+// SHOW DATABASE ID
+public class ShowDbIdStmt extends ShowStmt {
+    private long dbId;
+
+    public ShowDbIdStmt(long dbId) {
+        this.dbId = dbId;
+    }
+
+    public long getDbId() {
+        return dbId;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws AnalysisException {
+        // check access first
+        if 
(!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"SHOW DATABASE");
+        }
+    }
+
+    @Override
+    public String toSql() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("SHOW");
+        sb.append(" DATABASE ");
+        sb.append(this.dbId);
+        return sb.toString();
+    }
+
+    @Override
+    public String toString() {
+        return toSql();
+    }
+
+    @Override
+    public ShowResultSetMetaData getMetaData() {
+        ShowResultSetMetaData.Builder builder = 
ShowResultSetMetaData.builder();
+        builder.addColumn(new Column("DbName", ScalarType.createVarchar(30)));
+        return builder.build();
+    }
+}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionIdStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionIdStmt.java
new file mode 100644
index 0000000..05e6ba5
--- /dev/null
+++ 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowPartitionIdStmt.java
@@ -0,0 +1,74 @@
+// 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.
+
+package org.apache.doris.analysis;
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.ShowResultSetMetaData;
+
+// SHOW PARTITION ID
+public class ShowPartitionIdStmt extends ShowStmt {
+    private long partitionId;
+
+    public ShowPartitionIdStmt(long partitionId) {
+        this.partitionId = partitionId;
+    }
+
+    public long getPartitionId() {
+        return partitionId;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws AnalysisException {
+        // check access first
+        if 
(!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"SHOW PARTITION");
+        }
+    }
+
+    @Override
+    public String toSql() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("SHOW");
+        sb.append(" PARTITION ");
+        sb.append(this.partitionId);
+        return sb.toString();
+    }
+
+    @Override
+    public String toString() {
+        return toSql();
+    }
+
+    @Override
+    public ShowResultSetMetaData getMetaData() {
+        ShowResultSetMetaData.Builder builder = 
ShowResultSetMetaData.builder();
+        builder.addColumn(new Column("DbName", ScalarType.createVarchar(30)));
+        builder.addColumn(new Column("TableName", 
ScalarType.createVarchar(30)));
+        builder.addColumn(new Column("PartitionName", 
ScalarType.createVarchar(30)));
+        builder.addColumn(new Column("DbId", ScalarType.createVarchar(30)));
+        builder.addColumn(new Column("TableId", ScalarType.createVarchar(30)));
+        return builder.build();
+    }
+}
diff --git 
a/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowTableIdStmt.java 
b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowTableIdStmt.java
new file mode 100644
index 0000000..7f0f095
--- /dev/null
+++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/ShowTableIdStmt.java
@@ -0,0 +1,73 @@
+// 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.
+
+package org.apache.doris.analysis;
+
+
+import org.apache.doris.catalog.Catalog;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.mysql.privilege.PrivPredicate;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.ShowResultSetMetaData;
+
+// SHOW TABLE ID
+public class ShowTableIdStmt extends ShowStmt {
+    private long tableId;
+
+    public ShowTableIdStmt(long tableId) {
+        this.tableId = tableId;
+    }
+
+    public long getTableId() {
+        return tableId;
+    }
+
+    @Override
+    public void analyze(Analyzer analyzer) throws AnalysisException {
+        // check access first
+        if 
(!Catalog.getCurrentCatalog().getAuth().checkGlobalPriv(ConnectContext.get(), 
PrivPredicate.ADMIN)) {
+            
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, 
"SHOW TABLE");
+        }
+    }
+
+    @Override
+    public String toSql() {
+        StringBuilder sb = new StringBuilder();
+        sb.append("SHOW");
+        sb.append(" TABLE ");
+        sb.append(this.tableId);
+        return sb.toString();
+    }
+
+    @Override
+    public String toString() {
+        return toSql();
+    }
+
+    @Override
+    public ShowResultSetMetaData getMetaData() {
+        ShowResultSetMetaData.Builder builder = 
ShowResultSetMetaData.builder();
+        builder.addColumn(new Column("DbName", ScalarType.createVarchar(30)));
+        builder.addColumn(new Column("TableName", 
ScalarType.createVarchar(30)));
+        builder.addColumn(new Column("DbId", ScalarType.createVarchar(30)));
+        return builder.build();
+    }
+}
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 0ac3ec0..1e9a006 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
@@ -35,6 +35,7 @@ import org.apache.doris.analysis.ShowCreateDbStmt;
 import org.apache.doris.analysis.ShowCreateFunctionStmt;
 import org.apache.doris.analysis.ShowCreateTableStmt;
 import org.apache.doris.analysis.ShowDataStmt;
+import org.apache.doris.analysis.ShowDbIdStmt;
 import org.apache.doris.analysis.ShowDbStmt;
 import org.apache.doris.analysis.ShowDeleteStmt;
 import org.apache.doris.analysis.ShowDynamicPartitionStmt;
@@ -47,6 +48,7 @@ import org.apache.doris.analysis.ShowIndexStmt;
 import org.apache.doris.analysis.ShowLoadStmt;
 import org.apache.doris.analysis.ShowLoadWarningsStmt;
 import org.apache.doris.analysis.ShowMigrationsStmt;
+import org.apache.doris.analysis.ShowPartitionIdStmt;
 import org.apache.doris.analysis.ShowPartitionsStmt;
 import org.apache.doris.analysis.ShowPluginsStmt;
 import org.apache.doris.analysis.ShowProcStmt;
@@ -63,6 +65,7 @@ import org.apache.doris.analysis.ShowSmallFilesStmt;
 import org.apache.doris.analysis.ShowSnapshotStmt;
 import org.apache.doris.analysis.ShowStmt;
 import org.apache.doris.analysis.ShowStreamLoadStmt;
+import org.apache.doris.analysis.ShowTableIdStmt;
 import org.apache.doris.analysis.ShowTableStatusStmt;
 import org.apache.doris.analysis.ShowTableStmt;
 import org.apache.doris.analysis.ShowTabletStmt;
@@ -187,10 +190,14 @@ public class ShowExecutor {
             handleHelp();
         } else if (stmt instanceof ShowDbStmt) {
             handleShowDb();
+        } else if (stmt instanceof ShowDbIdStmt) {
+            handleShowDbId();
         } else if (stmt instanceof ShowTableStmt) {
             handleShowTable();
         } else if (stmt instanceof ShowTableStatusStmt) {
             handleShowTableStatus();
+        } else if (stmt instanceof ShowTableIdStmt) {
+            handleShowTableId();
         } else if (stmt instanceof DescribeStmt) {
             handleDescribe();
         } else if (stmt instanceof ShowCreateTableStmt) {
@@ -231,6 +238,8 @@ public class ShowExecutor {
             handleShowCollation();
         } else if (stmt instanceof ShowPartitionsStmt) {
             handleShowPartitions();
+        } else if (stmt instanceof ShowPartitionIdStmt) {
+            handleShowPartitionId();
         } else if (stmt instanceof ShowTabletStmt) {
             handleShowTablet();
         } else if (stmt instanceof ShowBackupStmt) {
@@ -452,6 +461,80 @@ public class ShowExecutor {
         resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
     }
 
+    private void handleShowDbId() throws AnalysisException {
+        ShowDbIdStmt showStmt = (ShowDbIdStmt) stmt;
+        long dbId = showStmt.getDbId();
+        List<List<String>> rows = Lists.newArrayList();
+        Catalog catalog = ctx.getCatalog();
+        Database database = catalog.getDb(dbId);
+        if (database != null) {
+            List<String> row = new ArrayList<>();
+            row.add(database.getFullName());
+            rows.add(row);
+        }
+        resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+    }
+
+    private void handleShowTableId() throws AnalysisException {
+        ShowTableIdStmt showStmt = (ShowTableIdStmt) stmt;
+        long tableId = showStmt.getTableId();
+        List<List<String>> rows = Lists.newArrayList();
+        Catalog catalog = ctx.getCatalog();
+        List<Long> dbIds = catalog.getDbIds();
+        for (long dbId : dbIds) {
+            Database database = catalog.getDb(dbId);
+            if (database == null) {
+                continue;
+            }
+            Table table = database.getTable(tableId);
+            if (table != null) {
+                List<String> row = new ArrayList<>();
+                row.add(database.getFullName());
+                row.add(table.getName());
+                row.add(String.valueOf(database.getId()));
+                rows.add(row);
+                break;
+            }
+        }
+        resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+    }
+
+    private void handleShowPartitionId() throws AnalysisException {
+        ShowPartitionIdStmt showStmt = (ShowPartitionIdStmt) stmt;
+        long partitionId = showStmt.getPartitionId();
+        List<List<String>> rows = Lists.newArrayList();
+        Catalog catalog = ctx.getCatalog();
+        List<Long> dbIds = catalog.getDbIds();
+        for (long dbId : dbIds) {
+            Database database = catalog.getDb(dbId);
+            if (database == null) {
+                continue;
+            }
+            List<Table> tables = database.getTables();
+            for (Table tbl : tables) {
+                if (tbl instanceof OlapTable) {
+                    tbl.readLock();
+                    try {
+                        Partition partition = ((OlapTable) 
tbl).getPartition(partitionId);
+                        if (partition != null) {
+                            List<String> row = new ArrayList<>();
+                            row.add(database.getFullName());
+                            row.add(tbl.getName());
+                            row.add(partition.getName());
+                            row.add(String.valueOf(database.getId()));
+                            row.add(String.valueOf(tbl.getId()));
+                            rows.add(row);
+                            break;
+                        }
+                    } finally {
+                        tbl.readUnlock();
+                    }
+                }
+            }
+        }
+        resultSet = new ShowResultSet(showStmt.getMetaData(), rows);
+    }
+
     // Show databases statement
     private void handleShowDb() throws AnalysisException {
         ShowDbStmt showDbStmt = (ShowDbStmt) stmt;
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowDbIdStmtTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowDbIdStmtTest.java
new file mode 100644
index 0000000..d2b38eb
--- /dev/null
+++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowDbIdStmtTest.java
@@ -0,0 +1,53 @@
+// 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.
+
+package org.apache.doris.analysis;
+
+import mockit.Mocked;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.UserException;
+import org.apache.doris.mysql.privilege.MockedAuth;
+import org.apache.doris.mysql.privilege.PaloAuth;
+import org.apache.doris.qe.ConnectContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ShowDbIdStmtTest {
+    private Analyzer analyzer;
+
+    @Mocked
+    private PaloAuth auth;
+    @Mocked
+    private ConnectContext ctx;
+
+    @Before
+    public void setUp() {
+        analyzer = AccessTestUtil.fetchAdminAnalyzer(true);
+        MockedAuth.mockedAuth(auth);
+        MockedAuth.mockedConnectContext(ctx, "root", "192.168.1.1");
+    }
+
+    @Test
+    public void testNormal() throws UserException, AnalysisException  {
+        ShowDbIdStmt stmt = new ShowDbIdStmt(123456);
+        stmt.analyze(analyzer);
+        Assert.assertEquals("SHOW DATABASE 123456", stmt.toString());
+        Assert.assertEquals(1, stmt.getMetaData().getColumnCount());
+        Assert.assertEquals("DbName", 
stmt.getMetaData().getColumn(0).getName());
+    }
+}
\ No newline at end of file
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowPartitionIdStmtTest.java
 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowPartitionIdStmtTest.java
new file mode 100644
index 0000000..346124b
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowPartitionIdStmtTest.java
@@ -0,0 +1,58 @@
+// 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.
+
+package org.apache.doris.analysis;
+
+import mockit.Mocked;
+import org.apache.doris.mysql.privilege.MockedAuth;
+import org.apache.doris.mysql.privilege.PaloAuth;
+import org.apache.doris.qe.ConnectContext;
+import org.junit.Assert;
+import org.junit.Before;
+import org.junit.Test;
+
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.common.UserException;
+
+public class ShowPartitionIdStmtTest {
+    private Analyzer analyzer;
+
+    @Mocked
+    private PaloAuth auth;
+    @Mocked
+    private ConnectContext ctx;
+
+    @Before
+    public void setUp() {
+        analyzer = AccessTestUtil.fetchAdminAnalyzer(true);
+        MockedAuth.mockedAuth(auth);
+        MockedAuth.mockedConnectContext(ctx, "root", "192.168.1.1");
+    }
+
+    @Test
+    public void testNormal() throws UserException, AnalysisException  {
+        ShowPartitionIdStmt stmt = new ShowPartitionIdStmt(123456);
+        stmt.analyze(analyzer);
+        Assert.assertEquals("SHOW PARTITION 123456", stmt.toString());
+        Assert.assertEquals(5, stmt.getMetaData().getColumnCount());
+        Assert.assertEquals("DbName", 
stmt.getMetaData().getColumn(0).getName());
+        Assert.assertEquals("TableName", 
stmt.getMetaData().getColumn(1).getName());
+        Assert.assertEquals("PartitionName", 
stmt.getMetaData().getColumn(2).getName());
+        Assert.assertEquals("DbId", stmt.getMetaData().getColumn(3).getName());
+        Assert.assertEquals("TableId", 
stmt.getMetaData().getColumn(4).getName());
+    }
+}
\ No newline at end of file
diff --git 
a/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowTableIdStmtTest.java 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowTableIdStmtTest.java
new file mode 100644
index 0000000..995208a
--- /dev/null
+++ 
b/fe/fe-core/src/test/java/org/apache/doris/analysis/ShowTableIdStmtTest.java
@@ -0,0 +1,51 @@
+// 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.
+
+package org.apache.doris.analysis;
+
+import mockit.Mocked;
+import org.apache.doris.common.*;
+import org.apache.doris.mysql.privilege.*;
+import org.apache.doris.qe.*;
+import org.junit.*;
+
+public class ShowTableIdStmtTest {
+    private Analyzer analyzer;
+
+    @Mocked
+    private PaloAuth auth;
+    @Mocked
+    private ConnectContext ctx;
+
+    @Before
+    public void setUp() {
+        analyzer = AccessTestUtil.fetchAdminAnalyzer(true);
+        MockedAuth.mockedAuth(auth);
+        MockedAuth.mockedConnectContext(ctx, "root", "192.168.1.1");
+    }
+
+    @Test
+    public void testNormal() throws UserException, AnalysisException  {
+        ShowTableIdStmt stmt = new ShowTableIdStmt(123456);
+        stmt.analyze(analyzer);
+        Assert.assertEquals("SHOW TABLE 123456", stmt.toString());
+        Assert.assertEquals(3, stmt.getMetaData().getColumnCount());
+        Assert.assertEquals("DbName", 
stmt.getMetaData().getColumn(0).getName());
+        Assert.assertEquals("TableName", 
stmt.getMetaData().getColumn(1).getName());
+        Assert.assertEquals("DbId", stmt.getMetaData().getColumn(2).getName());
+    }
+}
\ No newline at end of file

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

Reply via email to