Skip to content

Commit 045f590

Browse files
authored
[Feat] (Nereids)support showTrash Command (#44352)
Issue Number: close #42763
1 parent 738d0bf commit 045f590

5 files changed

Lines changed: 113 additions & 0 deletions

File tree

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -222,6 +222,7 @@
222222
import org.apache.doris.nereids.DorisParser.ShowStorageEnginesContext;
223223
import org.apache.doris.nereids.DorisParser.ShowTableIdContext;
224224
import org.apache.doris.nereids.DorisParser.ShowTabletsBelongContext;
225+
import org.apache.doris.nereids.DorisParser.ShowTrashContext;
225226
import org.apache.doris.nereids.DorisParser.ShowVariablesContext;
226227
import org.apache.doris.nereids.DorisParser.ShowViewContext;
227228
import org.apache.doris.nereids.DorisParser.ShowWhitelistContext;
@@ -482,6 +483,7 @@
482483
import org.apache.doris.nereids.trees.plans.commands.ShowStorageEnginesCommand;
483484
import org.apache.doris.nereids.trees.plans.commands.ShowTableIdCommand;
484485
import org.apache.doris.nereids.trees.plans.commands.ShowTabletsBelongCommand;
486+
import org.apache.doris.nereids.trees.plans.commands.ShowTrashCommand;
485487
import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand;
486488
import org.apache.doris.nereids.trees.plans.commands.ShowViewCommand;
487489
import org.apache.doris.nereids.trees.plans.commands.ShowWhiteListCommand;
@@ -4111,6 +4113,11 @@ public SetDefaultStorageVaultCommand visitSetDefaultStorageVault(SetDefaultStora
41114113
return new SetDefaultStorageVaultCommand(stripQuotes(ctx.identifier().getText()));
41124114
}
41134115

4116+
@Override
4117+
public LogicalPlan visitShowTrash(ShowTrashContext ctx) {
4118+
return new ShowTrashCommand();
4119+
}
4120+
41144121
@Override
41154122
public Object visitRefreshCatalog(RefreshCatalogContext ctx) {
41164123
if (ctx.name != null) {

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -199,6 +199,7 @@ public enum PlanType {
199199
SHOW_ROLE_COMMAND,
200200
SHOW_STORAGE_ENGINES_COMMAND,
201201
SHOW_TABLE_ID_COMMAND,
202+
SHOW_TRASH_COMMAND,
202203
SHOW_VARIABLES_COMMAND,
203204
SHOW_AUTHORS_COMMAND,
204205
SHOW_VIEW_COMMAND,
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
package org.apache.doris.nereids.trees.plans.commands;
19+
20+
import org.apache.doris.catalog.Column;
21+
import org.apache.doris.catalog.Env;
22+
import org.apache.doris.catalog.ScalarType;
23+
import org.apache.doris.common.proc.TrashProcDir;
24+
import org.apache.doris.nereids.trees.plans.PlanType;
25+
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
26+
import org.apache.doris.qe.ConnectContext;
27+
import org.apache.doris.qe.ShowResultSet;
28+
import org.apache.doris.qe.ShowResultSetMetaData;
29+
import org.apache.doris.qe.StmtExecutor;
30+
import org.apache.doris.system.Backend;
31+
32+
import com.google.common.collect.ImmutableMap;
33+
import com.google.common.collect.Lists;
34+
35+
import java.util.List;
36+
37+
/**
38+
* show trash command
39+
*/
40+
public class ShowTrashCommand extends ShowCommand {
41+
private List<Backend> backends = Lists.newArrayList();
42+
43+
public ShowTrashCommand() {
44+
super(PlanType.SHOW_TRASH_COMMAND);
45+
}
46+
47+
public List<Backend> getBackends() {
48+
return backends;
49+
}
50+
51+
public ShowResultSetMetaData getMetaData() {
52+
ShowResultSetMetaData.Builder builder = ShowResultSetMetaData.builder();
53+
for (String title : TrashProcDir.TITLE_NAMES) {
54+
builder.addColumn(new Column(title, ScalarType.createVarchar(30)));
55+
}
56+
return builder.build();
57+
}
58+
59+
private ShowResultSet handleShowTrash() throws Exception {
60+
ImmutableMap<Long, Backend> backendsInfo = Env.getCurrentSystemInfo().getAllBackendsByAllCluster();
61+
for (Backend backend : backendsInfo.values()) {
62+
this.backends.add(backend);
63+
}
64+
List<List<String>> infos = Lists.newArrayList();
65+
TrashProcDir.getTrashInfo(backends, infos);
66+
return new ShowResultSet(getMetaData(), infos);
67+
}
68+
69+
@Override
70+
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
71+
return visitor.visitShowTrashCommand(this, context);
72+
}
73+
74+
@Override
75+
public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
76+
return handleShowTrash();
77+
}
78+
}

‎fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@
8181
import org.apache.doris.nereids.trees.plans.commands.ShowStorageEnginesCommand;
8282
import org.apache.doris.nereids.trees.plans.commands.ShowTableIdCommand;
8383
import org.apache.doris.nereids.trees.plans.commands.ShowTabletsBelongCommand;
84+
import org.apache.doris.nereids.trees.plans.commands.ShowTrashCommand;
8485
import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand;
8586
import org.apache.doris.nereids.trees.plans.commands.ShowViewCommand;
8687
import org.apache.doris.nereids.trees.plans.commands.ShowWhiteListCommand;
@@ -391,6 +392,10 @@ default R visitShowTableIdCommand(ShowTableIdCommand showTableIdCommand, C conte
391392
return visitCommand(showTableIdCommand, context);
392393
}
393394

395+
default R visitShowTrashCommand(ShowTrashCommand showTrashCommand, C context) {
396+
return visitCommand(showTrashCommand, context);
397+
}
398+
394399
default R visitShowPrivilegesCommand(ShowPrivilegesCommand showPrivilegesCommand, C context) {
395400
return visitCommand(showPrivilegesCommand, context);
396401
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Licensed to the Apache Software Foundation (ASF) under one
2+
// or more contributor license agreements. See the NOTICE file
3+
// distributed with this work for additional information
4+
// regarding copyright ownership. The ASF licenses this file
5+
// to you under the Apache License, Version 2.0 (the
6+
// "License"); you may not use this file except in compliance
7+
// with the License. You may obtain a copy of the License at
8+
//
9+
// http://www.apache.org/licenses/LICENSE-2.0
10+
//
11+
// Unless required by applicable law or agreed to in writing,
12+
// software distributed under the License is distributed on an
13+
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
14+
// KIND, either express or implied. See the License for the
15+
// specific language governing permissions and limitations
16+
// under the License.
17+
18+
suite("show_trash_nereids") {
19+
// can not use qt command since the output change based on cluster and backend ip
20+
checkNereidsExecute("""show trash;""")
21+
checkNereidsExecute("""show trash on "127.0.0.1:9050";""")
22+
}

0 commit comments

Comments
 (0)