From b3e730553e6e642949b4d3de9606ce950226de4d Mon Sep 17 00:00:00 2001 From: Astralidea Date: Mon, 18 Nov 2024 15:43:38 -0800 Subject: [PATCH 1/3] Fix show keys from support external catalog Signed-off-by: Astralidea --- fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java index ae20b132227c2..f9044fac0057b 100644 --- a/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java +++ b/fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java @@ -2177,7 +2177,11 @@ public ShowResultSet visitShowDynamicPartitionStatement(ShowDynamicPartitionStmt @Override public ShowResultSet visitShowIndexStatement(ShowIndexStmt statement, ConnectContext context) { List> rows = Lists.newArrayList(); - Database db = context.getGlobalStateMgr().getLocalMetastore().getDb(statement.getDbName()); + String catalogName = statement.getTableName().getCatalog(); + if (catalogName == null) { + catalogName = context.getCurrentCatalog(); + } + Database db = GlobalStateMgr.getCurrentState().getMetadataMgr().getDb(catalogName, statement.getDbName()); MetaUtils.checkDbNullAndReport(db, statement.getDbName()); Table table = MetaUtils.getSessionAwareTable(context, db, statement.getTableName()); if (table == null) { From e91542838a2775f25d8d5243b91a904b91707484 Mon Sep 17 00:00:00 2001 From: Astralidea Date: Mon, 18 Nov 2024 18:10:52 -0800 Subject: [PATCH 2/3] Add UT. Signed-off-by: Astralidea --- .../test/java/com/starrocks/qe/ShowExecutorTest.java | 10 ++++++++++ 1 file changed, 10 insertions(+) diff --git a/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java b/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java index 32ada85042afe..83b788d2f069a 100644 --- a/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java @@ -51,6 +51,7 @@ import com.starrocks.catalog.ExpressionRangePartitionInfo; import com.starrocks.catalog.HashDistributionInfo; import com.starrocks.catalog.HiveTable; +import com.starrocks.catalog.Index; import com.starrocks.catalog.KeysType; import com.starrocks.catalog.ListPartitionInfoTest; import com.starrocks.catalog.MaterializedIndex; @@ -105,6 +106,7 @@ import com.starrocks.sql.ast.ShowDbStmt; import com.starrocks.sql.ast.ShowEnginesStmt; import com.starrocks.sql.ast.ShowGrantsStmt; +import com.starrocks.sql.ast.ShowIndexStmt; import com.starrocks.sql.ast.ShowMaterializedViewsStmt; import com.starrocks.sql.ast.ShowPartitionsStmt; import com.starrocks.sql.ast.ShowProcedureStmt; @@ -1173,6 +1175,14 @@ public Table getTable(String catalogName, String dbName, String tblName) { resultSet.getResultRows().get(0).get(1)); } + @Test + public void testShowKeysFromExternalTable() { + ShowIndexStmt stmt = new ShowIndexStmt("test_db", + new TableName(null, "test_db", "test_table")); + ShowResultSet resultSet = ShowExecutor.execute(stmt, ctx); + Assert.assertEquals(0, resultSet.getResultRows().size()); + } + @Test public void testShowCreateExternalCatalog() throws AnalysisException, DdlException { new MockUp() { From cd28daf75712e506744b8d3aca8f1360d25965c5 Mon Sep 17 00:00:00 2001 From: Astralidea Date: Mon, 18 Nov 2024 18:21:29 -0800 Subject: [PATCH 3/3] Fix Signed-off-by: Astralidea --- .../src/test/java/com/starrocks/qe/ShowExecutorTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java b/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java index 83b788d2f069a..d073fdf9b1180 100644 --- a/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/qe/ShowExecutorTest.java @@ -51,7 +51,6 @@ import com.starrocks.catalog.ExpressionRangePartitionInfo; import com.starrocks.catalog.HashDistributionInfo; import com.starrocks.catalog.HiveTable; -import com.starrocks.catalog.Index; import com.starrocks.catalog.KeysType; import com.starrocks.catalog.ListPartitionInfoTest; import com.starrocks.catalog.MaterializedIndex; @@ -1176,7 +1175,7 @@ public Table getTable(String catalogName, String dbName, String tblName) { } @Test - public void testShowKeysFromExternalTable() { + public void testShowKeysFromTable() { ShowIndexStmt stmt = new ShowIndexStmt("test_db", new TableName(null, "test_db", "test_table")); ShowResultSet resultSet = ShowExecutor.execute(stmt, ctx);