Skip to content

Commit

Permalink
[Enhancement] support like in show catalogs stmt (#53698)
Browse files Browse the repository at this point in the history
Signed-off-by: Rohit Satardekar <[email protected]>
  • Loading branch information
rohitrs1983 authored Jan 17, 2025
1 parent e798bdf commit 8b30bbe
Show file tree
Hide file tree
Showing 5 changed files with 26 additions and 7 deletions.
9 changes: 8 additions & 1 deletion fe/fe-core/src/main/java/com/starrocks/qe/ShowExecutor.java
Original file line number Diff line number Diff line change
Expand Up @@ -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<List<String>> 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))) {

Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -776,7 +776,7 @@ dropExternalCatalogStatement
;

showCatalogsStatement
: SHOW CATALOGS
: SHOW CATALOGS (LIKE pattern=string)?
;

alterCatalogStatement
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down

0 comments on commit 8b30bbe

Please sign in to comment.