Skip to content

Commit

Permalink
[Feat](nereids) support ShowTabletStorageFormat command in nereids ap…
Browse files Browse the repository at this point in the history
  • Loading branch information
rijeshkp committed Nov 18, 2024
1 parent 27132c8 commit cc32859
Show file tree
Hide file tree
Showing 6 changed files with 186 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ statementBase
| supportedShowStatement #supportedShowStatementAlias
| unsupportedStatement #unsupported
| supportedRecoverStatement #supportedRecoverStatementAlias
| supportedAdminStatement #supportedAdminStatementAlias
;


Expand Down Expand Up @@ -208,7 +209,8 @@ supportedShowStatement
| SHOW STORAGE? ENGINES #showStorageEngines
| SHOW CREATE MATERIALIZED VIEW mvName=identifier
ON tableName=multipartIdentifier #showCreateMaterializedView
| SHOW FRONTENDS name=identifier? #showFrontends
| SHOW FRONTENDS name=identifier? #showFrontends
| SHOW TABLET STORAGE FORMAT VERBOSE? #showTabletStorageFormat
;

unsupportedOtherStatement
Expand Down Expand Up @@ -334,7 +336,6 @@ unsupportedShowStatement
| SHOW CONVERT_LSC ((FROM | IN) database=multipartIdentifier)? #showConvertLsc
| SHOW REPLICA STATUS FROM baseTableRef wildWhere? #showReplicaStatus
| SHOW REPLICA DISTRIBUTION FROM baseTableRef #showREplicaDistribution
| SHOW TABLET STORAGE FORMAT VERBOSE? #showTabletStorageFormat
| SHOW TABLET DIAGNOSIS tabletId=INTEGER_VALUE #showDiagnoseTablet
| SHOW COPY ((FROM | IN) database=multipartIdentifier)?
whereClause? sortClause? limitClause? #showCopy
Expand Down Expand Up @@ -488,11 +489,14 @@ unsupportedAdminStatement
| ADMIN SET TABLE name=multipartIdentifier
PARTITION VERSION properties=propertyClause? #adminSetPartitionVersion
| ADMIN DIAGNOSE TABLET tabletId=INTEGER_VALUE #adminDiagnoseTablet
| ADMIN SHOW TABLET STORAGE FORMAT VERBOSE? #adminShowTabletStorageFormat
| ADMIN COPY TABLET tabletId=INTEGER_VALUE properties=propertyClause? #adminCopyTablet
| ADMIN SET TABLE name=multipartIdentifier STATUS properties=propertyClause? #adminSetTableStatus
;

supportedAdminStatement
: ADMIN SHOW TABLET STORAGE FORMAT VERBOSE? #adminShowTabletStorageFormat
;

baseTableRef
: multipartIdentifier optScanParams? tableSnapshot? specifiedPartition?
tabletList? tableAlias sample? relationHint?
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.apache.doris.mtmv.MTMVRefreshTriggerInfo;
import org.apache.doris.nereids.DorisParser;
import org.apache.doris.nereids.DorisParser.AddConstraintContext;
import org.apache.doris.nereids.DorisParser.AdminShowTabletStorageFormatContext;
import org.apache.doris.nereids.DorisParser.AggClauseContext;
import org.apache.doris.nereids.DorisParser.AggStateDataTypeContext;
import org.apache.doris.nereids.DorisParser.AliasQueryContext;
Expand Down Expand Up @@ -207,6 +208,7 @@
import org.apache.doris.nereids.DorisParser.ShowRepositoriesContext;
import org.apache.doris.nereids.DorisParser.ShowRolesContext;
import org.apache.doris.nereids.DorisParser.ShowStorageEnginesContext;
import org.apache.doris.nereids.DorisParser.ShowTabletStorageFormatContext;
import org.apache.doris.nereids.DorisParser.ShowVariablesContext;
import org.apache.doris.nereids.DorisParser.ShowViewContext;
import org.apache.doris.nereids.DorisParser.SimpleColumnDefContext;
Expand Down Expand Up @@ -449,6 +451,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowStorageEnginesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTabletStorageFormatCommand;
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.UnsetDefaultStorageVaultCommand;
Expand Down Expand Up @@ -4135,4 +4138,17 @@ public LogicalPlan visitRecoverDatabase(RecoverDatabaseContext ctx) {
public LogicalPlan visitDropRole(DropRoleContext ctx) {
return new DropRoleCommand(ctx.name.getText(), ctx.EXISTS() != null);
}

@Override
public LogicalPlan visitAdminShowTabletStorageFormat(AdminShowTabletStorageFormatContext ctx) {
boolean verbose = ctx.VERBOSE() != null;
return new ShowTabletStorageFormatCommand(verbose);
}

@Override
public LogicalPlan visitShowTabletStorageFormat(ShowTabletStorageFormatContext ctx) {
boolean verbose = ctx.VERBOSE() != null;
return new ShowTabletStorageFormatCommand(verbose);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -190,5 +190,6 @@ public enum PlanType {
RECOVER_DATABASE_COMMAND,
RECOVER_TABLE_COMMAND,
RECOVER_PARTITION_COMMAND,
REPLAY_COMMAND
REPLAY_COMMAND,
SHOW_TABLET_STORAGE_FORMAT_COMMAND
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
// 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.AnalysisException;
import org.apache.doris.common.DdlException;
import org.apache.doris.common.ErrorCode;
import org.apache.doris.common.ErrorReport;
import org.apache.doris.mysql.privilege.PrivPredicate;
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 org.apache.doris.task.AgentClient;
import org.apache.doris.thrift.TCheckStorageFormatResult;

import com.google.common.collect.Lists;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import java.util.ArrayList;
import java.util.List;

/**
* show tablet storage format command
*/
public class ShowTabletStorageFormatCommand extends ShowCommand {
public static final Logger LOG = LogManager.getLogger(ShowTabletStorageFormatCommand.class);
private final boolean verbose;

/**
* constructor
*/
public ShowTabletStorageFormatCommand(boolean verbose) {
super(PlanType.SHOW_TABLET_STORAGE_FORMAT_COMMAND);
this.verbose = verbose;
}

/**
* get Meta for show
*/
public ShowResultSetMetaData getMetaData() {
ShowResultSetMetaData.Builder builder = ShowResultSetMetaData.builder();
if (verbose) {
builder.addColumn(new Column("BackendId", ScalarType.createVarchar(30)))
.addColumn(new Column("TabletId", ScalarType.createVarchar(30)))
.addColumn(new Column("StorageFormat", ScalarType.createVarchar(30)));
} else {
builder.addColumn(new Column("BackendId", ScalarType.createVarchar(30)))
.addColumn(new Column("V1Count", ScalarType.createVarchar(30)))
.addColumn(new Column("V2Count", ScalarType.createVarchar(30)));
}
return builder.build();
}

@Override
public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception {
if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) {
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
PrivPredicate.ADMIN.getPrivs().toString());
}

List<List<String>> resultRowSet = Lists.newArrayList();
for (Backend be : Env.getCurrentSystemInfo().getAllBackendsByAllCluster().values()) {
if (be.isQueryAvailable() && be.isLoadAvailable()) {
AgentClient client = new AgentClient(be.getHost(), be.getBePort());
TCheckStorageFormatResult result = client.checkStorageFormat();
if (result == null) {
throw new AnalysisException("get tablet data from backend: " + be.getId() + "error.");
}
if (verbose) {
for (long tabletId : result.getV1Tablets()) {
List<String> row = new ArrayList<>();
row.add(String.valueOf(be.getId()));
row.add(String.valueOf(tabletId));
row.add("V1");
resultRowSet.add(row);
}
for (long tabletId : result.getV2Tablets()) {
List<String> row = new ArrayList<>();
row.add(String.valueOf(be.getId()));
row.add(String.valueOf(tabletId));
row.add("V2");
resultRowSet.add(row);
}
} else {
List<String> row = new ArrayList<>();
row.add(String.valueOf(be.getId()));
row.add(String.valueOf(result.getV1Tablets().size()));
row.add(String.valueOf(result.getV2Tablets().size()));
resultRowSet.add(row);
}
}
}
ShowResultSetMetaData showMetaData = getMetaData();
return new ShowResultSet(showMetaData, resultRowSet);
}

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

@Override
protected void checkSupportedInCloudMode() throws DdlException {
LOG.info("show tablet storage format not supported in cloud mode");
throw new DdlException("Unsupported operation");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowStorageEnginesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowTabletStorageFormatCommand;
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.UnsetDefaultStorageVaultCommand;
Expand Down Expand Up @@ -298,4 +299,9 @@ default R visitRecoverDatabaseCommand(RecoverDatabaseCommand recoverDatabaseComm
default R visitDropRoleCommand(DropRoleCommand dropRoleCommand, C context) {
return visitCommand(dropRoleCommand, context);
}

default R visitShowTabletStorageFormatCommand(ShowTabletStorageFormatCommand showTabletStorageFormatCommand,
C context) {
return visitCommand(showTabletStorageFormatCommand, context);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// 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("test_nereids_show_tablet_storage_format") {
checkNereidsExecute("""show tablet storage format;""")
checkNereidsExecute("""show tablet storage format verbose;""")
checkNereidsExecute("""admin show tablet storage format;""")
checkNereidsExecute("""admin show tablet storage format verbose;""")
}

0 comments on commit cc32859

Please sign in to comment.