Skip to content

Commit 1207435

Browse files
author
hegh1
committed
[Feature](sql) Support filtering backends by ID in SHOW BACKENDS command
1 parent 7d5e417 commit 1207435

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -421,6 +421,7 @@ supportedShowStatement
421421
| SHOW (WARNINGS | ERRORS) limitClause? #showWarningErrors
422422
| SHOW COUNT LEFT_PAREN ASTERISK RIGHT_PAREN (WARNINGS | ERRORS) #showWarningErrorCount
423423
| SHOW BACKENDS #showBackends
424+
| SHOW BACKENDS backendIds+=INTEGER_VALUE (COMMA backendIds+=INTEGER_VALUE)* #showBackendsWithIds
424425
| SHOW STAGES #showStages
425426
| SHOW REPLICA DISTRIBUTION FROM baseTableRef #showReplicaDistribution
426427
| SHOW RESOURCES wildWhere? sortClause? limitClause? #showResources

fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -355,6 +355,7 @@
355355
import org.apache.doris.nereids.DorisParser.ShowAnalyzeTaskContext;
356356
import org.apache.doris.nereids.DorisParser.ShowAuthorsContext;
357357
import org.apache.doris.nereids.DorisParser.ShowBackendsContext;
358+
import org.apache.doris.nereids.DorisParser.ShowBackendsWithIdsContext;
358359
import org.apache.doris.nereids.DorisParser.ShowBackupContext;
359360
import org.apache.doris.nereids.DorisParser.ShowBrokerContext;
360361
import org.apache.doris.nereids.DorisParser.ShowBuildIndexContext;
@@ -6180,6 +6181,14 @@ public LogicalPlan visitShowBackends(ShowBackendsContext ctx) {
61806181
return new ShowBackendsCommand();
61816182
}
61826183

6184+
@Override
6185+
public LogicalPlan visitShowBackendsWithIds(ShowBackendsWithIdsContext ctx) {
6186+
List<Long> backendIds = ctx.backendIds.stream()
6187+
.map(token -> Long.parseLong(token.getText()))
6188+
.collect(Collectors.toList());
6189+
return new ShowBackendsCommand(backendIds);
6190+
}
6191+
61836192
@Override
61846193
public LogicalPlan visitShowBackup(ShowBackupContext ctx) {
61856194
String dbName = null;

fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowBackendsCommand.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,18 +35,28 @@
3535
import org.apache.doris.qe.StmtExecutor;
3636

3737
import java.util.Comparator;
38+
import java.util.HashSet;
3839
import java.util.List;
40+
import java.util.Set;
41+
import java.util.stream.Collectors;
3942

4043
/**
4144
* show backends command
4245
*/
4346
public class ShowBackendsCommand extends ShowCommand {
4447

48+
private final List<Long> backendIds;
49+
4550
/**
4651
* constructor
4752
*/
4853
public ShowBackendsCommand() {
54+
this(null);
55+
}
56+
57+
public ShowBackendsCommand(List<Long> backendIds) {
4958
super(PlanType.SHOW_BACKENDS_COMMAND);
59+
this.backendIds = backendIds;
5060
}
5161

5262
public ShowResultSetMetaData getMetaData() {
@@ -66,6 +76,12 @@ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exc
6676
}
6777

6878
List<List<String>> backendInfos = BackendsProcDir.getBackendInfos();
79+
if (backendIds != null && !backendIds.isEmpty()) {
80+
Set<Long> idSet = new HashSet<>(backendIds);
81+
backendInfos = backendInfos.stream()
82+
.filter(info -> idSet.contains(Long.parseLong(info.get(0))))
83+
.collect(Collectors.toList());
84+
}
6985
backendInfos.sort(new Comparator<List<String>>() {
7086
@Override
7187
public int compare(List<String> o1, List<String> o2) {

0 commit comments

Comments
 (0)