Skip to content

Commit

Permalink
[Feat](nereids) support ShowTabletStorageFormat command in nereids
Browse files Browse the repository at this point in the history
  • Loading branch information
rijeshkp committed Dec 5, 2024
1 parent d58a972 commit c201770
Show file tree
Hide file tree
Showing 7 changed files with 181 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -262,6 +262,7 @@ supportedShowStatement
| SHOW WHITELIST #showWhitelist
| SHOW TABLETS BELONG
tabletIds+=INTEGER_VALUE (COMMA tabletIds+=INTEGER_VALUE)* #showTabletsBelong
| SHOW TABLET STORAGE FORMAT VERBOSE? #showTabletStorageFormat
;

supportedLoadStatement
Expand Down Expand Up @@ -364,7 +365,6 @@ unsupportedShowStatement
| SHOW (CLUSTERS | (COMPUTE GROUPS)) #showClusters
| SHOW CONVERT_LSC ((FROM | IN) database=multipartIdentifier)? #showConvertLsc
| SHOW REPLICA STATUS FROM baseTableRef wildWhere? #showReplicaStatus
| SHOW TABLET STORAGE FORMAT VERBOSE? #showTabletStorageFormat
| SHOW COPY ((FROM | IN) database=multipartIdentifier)?
whereClause? sortClause? limitClause? #showCopy
| SHOW WARM UP JOB wildWhere? #showWarmUpJob
Expand Down Expand Up @@ -489,6 +489,7 @@ supportedAdminStatement
| ADMIN DIAGNOSE TABLET tabletId=INTEGER_VALUE #adminDiagnoseTablet
| ADMIN SHOW REPLICA STATUS FROM baseTableRef (WHERE STATUS EQ|NEQ STRING_LITERAL)? #adminShowReplicaStatus
| ADMIN COMPACT TABLE baseTableRef (WHERE TYPE EQ STRING_LITERAL)? #adminCompactTable
| ADMIN SHOW TABLET STORAGE FORMAT VERBOSE? #adminShowTabletStorageFormat
;

supportedRecoverStatement
Expand All @@ -515,7 +516,6 @@ unsupportedAdminStatement
(COMMA backends+=STRING_LITERAL) RIGHT_PAREN)? #adminCleanTrash
| ADMIN SET TABLE name=multipartIdentifier
PARTITION VERSION properties=propertyClause? #adminSetPartitionVersion
| 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
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
import org.apache.doris.nereids.DorisParser.AdminDiagnoseTabletContext;
import org.apache.doris.nereids.DorisParser.AdminShowReplicaDistributionContext;
import org.apache.doris.nereids.DorisParser.AdminShowReplicaStatusContext;
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 @@ -267,6 +268,7 @@
import org.apache.doris.nereids.DorisParser.ShowSqlBlockRuleContext;
import org.apache.doris.nereids.DorisParser.ShowStorageEnginesContext;
import org.apache.doris.nereids.DorisParser.ShowTableIdContext;
import org.apache.doris.nereids.DorisParser.ShowTabletStorageFormatContext;
import org.apache.doris.nereids.DorisParser.ShowTabletsBelongContext;
import org.apache.doris.nereids.DorisParser.ShowTrashContext;
import org.apache.doris.nereids.DorisParser.ShowTriggersContext;
Expand Down Expand Up @@ -565,6 +567,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowSqlBlockRuleCommand;
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.ShowTabletStorageFormatCommand;
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.ShowTriggersCommand;
Expand Down Expand Up @@ -4936,4 +4939,15 @@ public LogicalPlan visitShowCollation(ShowCollationContext ctx) {
}
return new ShowCollationCommand(wild);
}

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

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

}
Original file line number Diff line number Diff line change
Expand Up @@ -231,6 +231,7 @@ public enum PlanType {
SHOW_STORAGE_ENGINES_COMMAND,
SHOW_TABLE_ID_COMMAND,
SHOW_TRASH_COMMAND,
SHOW_TABLET_STORAGE_FORMAT_COMMAND,
SHOW_TRIGGERS_COMMAND,
SHOW_VARIABLES_COMMAND,
SHOW_AUTHORS_COMMAND,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// 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);
}
}
}
return new ShowResultSet(getMetaData(), resultRowSet);
}

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

@Override
protected void checkSupportedInCloudMode(ConnectContext ctx) 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 @@ -112,6 +112,7 @@
import org.apache.doris.nereids.trees.plans.commands.ShowSqlBlockRuleCommand;
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.ShowTabletStorageFormatCommand;
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.ShowTriggersCommand;
Expand Down Expand Up @@ -585,4 +586,9 @@ default R visitCreateRoutineLoadCommand(CreateRoutineLoadCommand createRoutineLo
default R visitShowProcessListCommand(ShowProcessListCommand showProcessListCommand, C context) {
return visitCommand(showProcessListCommand, context);
}

default R visitShowTabletStorageFormatCommand(ShowTabletStorageFormatCommand showTabletStorageFormatCommand,
C context) {
return visitCommand(showTabletStorageFormatCommand, context);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@ suite("test_database_management_auth","p0,auth_call") {
String user = 'test_database_management_auth_user'
String pwd = 'C123_567p'
String dbName = 'test_database_management_auth_db'
def String show_dis_error_msg = "denied"
def String error_in_cloud = "denied"
//cloud-mode
if (isCloudMode()) {
def clusters = sql " SHOW CLUSTERS; "
assertTrue(!clusters.isEmpty())
def validCluster = clusters[0][0]
sql """GRANT USAGE_PRIV ON CLUSTER ${validCluster} TO ${user}""";
show_dis_error_msg = "Unsupported"
error_in_cloud = "Unsupported"
}

try_sql("DROP USER ${user}")
Expand Down Expand Up @@ -79,7 +79,7 @@ suite("test_database_management_auth","p0,auth_call") {
}
test {
sql """SHOW REPLICA DISTRIBUTION FROM tbl;"""
exception "${show_dis_error_msg}"
exception "${error_in_cloud}"
}
test {
sql """SHOW REPLICA STATUS FROM db1.tbl1;"""
Expand Down Expand Up @@ -107,7 +107,7 @@ suite("test_database_management_auth","p0,auth_call") {
}
test {
sql """show tablet storage format verbose;"""
exception "denied"
exception "${error_in_cloud}"
}
test {
sql """ADMIN CLEAN TRASH;"""
Expand Down
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 c201770

Please sign in to comment.