Skip to content

Commit b36e4b6

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

File tree

2 files changed

+18
-1
lines changed

2 files changed

+18
-1
lines changed

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -420,7 +420,8 @@ supportedShowStatement
420420
ON tableName=multipartIdentifier #showCreateMaterializedView
421421
| SHOW (WARNINGS | ERRORS) limitClause? #showWarningErrors
422422
| SHOW COUNT LEFT_PAREN ASTERISK RIGHT_PAREN (WARNINGS | ERRORS) #showWarningErrorCount
423-
| SHOW BACKENDS #showBackends
423+
| SHOW BACKENDS
424+
(ID=backendIds+=INTEGER_VALUE (COMMA backendIds+=INTEGER_VALUE)*)? #showBackends
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/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)