Skip to content

Commit

Permalink
[Feat] (Nereids)support showTrash Command (#44352)
Browse files Browse the repository at this point in the history
Issue Number: close #42763
  • Loading branch information
echo-hhj authored Nov 21, 2024
1 parent 738d0bf commit 045f590
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -222,6 +222,7 @@
import org.apache.doris.nereids.DorisParser.ShowStorageEnginesContext;
import org.apache.doris.nereids.DorisParser.ShowTableIdContext;
import org.apache.doris.nereids.DorisParser.ShowTabletsBelongContext;
import org.apache.doris.nereids.DorisParser.ShowTrashContext;
import org.apache.doris.nereids.DorisParser.ShowVariablesContext;
import org.apache.doris.nereids.DorisParser.ShowViewContext;
import org.apache.doris.nereids.DorisParser.ShowWhitelistContext;
Expand Down Expand Up @@ -482,6 +483,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowStorageEnginesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTableIdCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTabletsBelongCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTrashCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowViewCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowWhiteListCommand;
Expand Down Expand Up @@ -4111,6 +4113,11 @@ public SetDefaultStorageVaultCommand visitSetDefaultStorageVault(SetDefaultStora
return new SetDefaultStorageVaultCommand(stripQuotes(ctx.identifier().getText()));
}

@Override
public LogicalPlan visitShowTrash(ShowTrashContext ctx) {
return new ShowTrashCommand();
}

@Override
public Object visitRefreshCatalog(RefreshCatalogContext ctx) {
if (ctx.name != null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ public enum PlanType {
SHOW_ROLE_COMMAND,
SHOW_STORAGE_ENGINES_COMMAND,
SHOW_TABLE_ID_COMMAND,
SHOW_TRASH_COMMAND,
SHOW_VARIABLES_COMMAND,
SHOW_AUTHORS_COMMAND,
SHOW_VIEW_COMMAND,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

package org.apache.doris.nereids.trees.plans.commands;

import org.apache.doris.catalog.Column;
import org.apache.doris.catalog.Env;
import org.apache.doris.catalog.ScalarType;
import org.apache.doris.common.proc.TrashProcDir;
import org.apache.doris.nereids.trees.plans.PlanType;
import org.apache.doris.nereids.trees.plans.visitor.PlanVisitor;
import org.apache.doris.qe.ConnectContext;
import org.apache.doris.qe.ShowResultSet;
import org.apache.doris.qe.ShowResultSetMetaData;
import org.apache.doris.qe.StmtExecutor;
import org.apache.doris.system.Backend;

import com.google.common.collect.ImmutableMap;
import com.google.common.collect.Lists;

import java.util.List;

/**
* show trash command
*/
public class ShowTrashCommand extends ShowCommand {
private List<Backend> backends = Lists.newArrayList();

public ShowTrashCommand() {
super(PlanType.SHOW_TRASH_COMMAND);
}

public List<Backend> getBackends() {
return backends;
}

public ShowResultSetMetaData getMetaData() {
ShowResultSetMetaData.Builder builder = ShowResultSetMetaData.builder();
for (String title : TrashProcDir.TITLE_NAMES) {
builder.addColumn(new Column(title, ScalarType.createVarchar(30)));
}
return builder.build();
}

private ShowResultSet handleShowTrash() throws Exception {
ImmutableMap<Long, Backend> backendsInfo = Env.getCurrentSystemInfo().getAllBackendsByAllCluster();
for (Backend backend : backendsInfo.values()) {
this.backends.add(backend);
}
List<List<String>> infos = Lists.newArrayList();
TrashProcDir.getTrashInfo(backends, infos);
return new ShowResultSet(getMetaData(), infos);
}

@Override
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitShowTrashCommand(this, context);
}

@Override
public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
return handleShowTrash();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowStorageEnginesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTableIdCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTabletsBelongCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTrashCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowViewCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowWhiteListCommand;
Expand Down Expand Up @@ -391,6 +392,10 @@ default R visitShowTableIdCommand(ShowTableIdCommand showTableIdCommand, C conte
return visitCommand(showTableIdCommand, context);
}

default R visitShowTrashCommand(ShowTrashCommand showTrashCommand, C context) {
return visitCommand(showTrashCommand, context);
}

default R visitShowPrivilegesCommand(ShowPrivilegesCommand showPrivilegesCommand, C context) {
return visitCommand(showPrivilegesCommand, context);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the Apache Software Foundation (ASF) under one
// or more contributor license agreements. See the NOTICE file
// distributed with this work for additional information
// regarding copyright ownership. The ASF licenses this file
// to you under the Apache License, Version 2.0 (the
// "License"); you may not use this file except in compliance
// with the License. You may obtain a copy of the License at
//
// http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing,
// software distributed under the License is distributed on an
// "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
// KIND, either express or implied. See the License for the
// specific language governing permissions and limitations
// under the License.

suite("show_trash_nereids") {
// can not use qt command since the output change based on cluster and backend ip
checkNereidsExecute("""show trash;""")
checkNereidsExecute("""show trash on "127.0.0.1:9050";""")
}

0 comments on commit 045f590

Please sign in to comment.