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 1fa5c5e05c26b..a121f085a9366 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 @@ -2379,7 +2379,14 @@ public ShowResultSet visitShowUserStatement(ShowUserStmt statement, ConnectConte public ShowResultSet visitShowCatalogsStatement(ShowCatalogsStmt statement, ConnectContext context) { GlobalStateMgr globalStateMgr = GlobalStateMgr.getCurrentState(); CatalogMgr catalogMgr = globalStateMgr.getCatalogMgr(); + PatternMatcher matcher = null; + if (statement.getPattern() != null) { + matcher = PatternMatcher.createMysqlPattern(statement.getPattern(), + CaseSensibility.CONFIG.getCaseSensibility()); + } + PatternMatcher finalMatcher = matcher; List> rowSet = catalogMgr.getCatalogsInfo().stream() + .filter(rowMatch -> finalMatcher == null || finalMatcher.match(rowMatch.get(0))) .filter(row -> { if (!InternalCatalog.DEFAULT_INTERNAL_CATALOG_NAME.equals(row.get(0))) { @@ -2394,7 +2401,7 @@ public ShowResultSet visitShowCatalogsStatement(ShowCatalogsStmt statement, Conn return true; } return true; - } + } ) .sorted(Comparator.comparing(o -> o.get(0))).collect(Collectors.toList()); return new ShowResultSet(statement.getMetaData(), rowSet); diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/ast/ShowCatalogsStmt.java b/fe/fe-core/src/main/java/com/starrocks/sql/ast/ShowCatalogsStmt.java index d7659e5089e51..a81fbc1858933 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/ast/ShowCatalogsStmt.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/ast/ShowCatalogsStmt.java @@ -29,12 +29,19 @@ public class ShowCatalogsStmt extends ShowStmt { .addColumn(new Column("Comment", ScalarType.createVarchar(30))) .build(); - public ShowCatalogsStmt() { - this(NodePosition.ZERO); + private final String pattern; + + public ShowCatalogsStmt(String pattern) { + this(pattern, NodePosition.ZERO); } - public ShowCatalogsStmt(NodePosition pos) { + public ShowCatalogsStmt(String pattern, NodePosition pos) { super(pos); + this.pattern = pattern; + } + + public String getPattern() { + return pattern; } @Override diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java b/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java index 333fb4c1ad1e7..4bb009d6fa4cd 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java +++ b/fe/fe-core/src/main/java/com/starrocks/sql/parser/AstBuilder.java @@ -2197,7 +2197,12 @@ public ParseNode visitShowCreateExternalCatalogStatement( @Override public ParseNode visitShowCatalogsStatement(StarRocksParser.ShowCatalogsStatementContext context) { - return new ShowCatalogsStmt(createPos(context)); + NodePosition pos = createPos(context); + if (context.pattern != null) { + StringLiteral stringLiteral = (StringLiteral) visit(context.pattern); + return new ShowCatalogsStmt(stringLiteral.getValue(), pos); + } + return new ShowCatalogsStmt(null, createPos(context)); } @Override diff --git a/fe/fe-core/src/main/java/com/starrocks/sql/parser/StarRocks.g4 b/fe/fe-core/src/main/java/com/starrocks/sql/parser/StarRocks.g4 index 7e4d9cf83608e..5670d248bba1d 100644 --- a/fe/fe-core/src/main/java/com/starrocks/sql/parser/StarRocks.g4 +++ b/fe/fe-core/src/main/java/com/starrocks/sql/parser/StarRocks.g4 @@ -776,7 +776,7 @@ dropExternalCatalogStatement ; showCatalogsStatement - : SHOW CATALOGS + : SHOW CATALOGS (LIKE pattern=string)? ; alterCatalogStatement diff --git a/fe/fe-core/src/test/java/com/starrocks/analysis/ShowCatalogsStmtTest.java b/fe/fe-core/src/test/java/com/starrocks/analysis/ShowCatalogsStmtTest.java index 7f6fc165475cd..5e3696b5b7a67 100644 --- a/fe/fe-core/src/test/java/com/starrocks/analysis/ShowCatalogsStmtTest.java +++ b/fe/fe-core/src/test/java/com/starrocks/analysis/ShowCatalogsStmtTest.java @@ -67,7 +67,7 @@ public static void beforeClass() throws Exception { @Test public void testShowCatalogsNormal() throws AnalysisException, DdlException { - ShowCatalogsStmt stmt = new ShowCatalogsStmt(); + ShowCatalogsStmt stmt = new ShowCatalogsStmt(null); ShowResultSet resultSet = ShowExecutor.execute(stmt, ctx); ShowResultSetMetaData metaData = resultSet.getMetaData(); Assert.assertEquals("Catalog", metaData.getColumn(0).getName());