This is an automated email from the ASF dual-hosted git repository. starocean999 pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/doris.git
The following commit(s) were added to refs/heads/master by this push: new b761e4ec34b [Enhancement] (nereids)implement showDiagnoseTabletCommand in nereids (#43159) b761e4ec34b is described below commit b761e4ec34be7a0bba2fb805e604e7c8283032cf Author: Sridhar R Manikarnike <sridhar.n...@gmail.com> AuthorDate: Thu Nov 28 12:19:48 2024 +0530 [Enhancement] (nereids)implement showDiagnoseTabletCommand in nereids (#43159) Issue Number: close #42836 implement showDiagnoseTabletCommand in nereids --- .../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +- .../doris/nereids/parser/LogicalPlanBuilder.java | 8 +++ .../apache/doris/nereids/trees/plans/PlanType.java | 1 + .../plans/commands/ShowDiagnoseTabletCommand.java | 84 ++++++++++++++++++++++ .../trees/plans/visitor/CommandVisitor.java | 5 ++ .../show/test_show_diagnose_tablet.groovy | 39 ++++++++++ 6 files changed, 138 insertions(+), 1 deletion(-) diff --git a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 index 6444f533ac0..1b1e218a958 100644 --- a/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 +++ b/fe/fe-core/src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 @@ -242,6 +242,7 @@ supportedShowStatement | SHOW BACKENDS #showBackends | SHOW REPLICA DISTRIBUTION FROM baseTableRef #showReplicaDistribution | SHOW FULL? TRIGGERS ((FROM | IN) database=multipartIdentifier)? wildWhere? #showTriggers + | SHOW TABLET DIAGNOSIS tabletId=INTEGER_VALUE #showDiagnoseTablet | SHOW FRONTENDS name=identifier? #showFrontends | SHOW TABLE tableId=INTEGER_VALUE #showTableId | SHOW WHITELIST #showWhitelist @@ -355,7 +356,6 @@ unsupportedShowStatement | SHOW CONVERT_LSC ((FROM | IN) database=multipartIdentifier)? #showConvertLsc | SHOW REPLICA STATUS FROM baseTableRef wildWhere? #showReplicaStatus | SHOW TABLET STORAGE FORMAT VERBOSE? #showTabletStorageFormat - | SHOW TABLET DIAGNOSIS tabletId=INTEGER_VALUE #showDiagnoseTablet | SHOW COPY ((FROM | IN) database=multipartIdentifier)? whereClause? sortClause? limitClause? #showCopy | SHOW WARM UP JOB wildWhere? #showWarmUpJob diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java index f2119ddd61d..2db26dc1501 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/parser/LogicalPlanBuilder.java @@ -232,6 +232,7 @@ import org.apache.doris.nereids.DorisParser.ShowCreateProcedureContext; import org.apache.doris.nereids.DorisParser.ShowCreateTableContext; import org.apache.doris.nereids.DorisParser.ShowCreateViewContext; import org.apache.doris.nereids.DorisParser.ShowDeleteContext; +import org.apache.doris.nereids.DorisParser.ShowDiagnoseTabletContext; import org.apache.doris.nereids.DorisParser.ShowDynamicPartitionContext; import org.apache.doris.nereids.DorisParser.ShowEventsContext; import org.apache.doris.nereids.DorisParser.ShowFrontendsContext; @@ -517,6 +518,7 @@ import org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand; import org.apache.doris.nereids.trees.plans.commands.ShowCreateTableCommand; import org.apache.doris.nereids.trees.plans.commands.ShowCreateViewCommand; import org.apache.doris.nereids.trees.plans.commands.ShowDeleteCommand; +import org.apache.doris.nereids.trees.plans.commands.ShowDiagnoseTabletCommand; import org.apache.doris.nereids.trees.plans.commands.ShowDynamicPartitionCommand; import org.apache.doris.nereids.trees.plans.commands.ShowEventsCommand; import org.apache.doris.nereids.trees.plans.commands.ShowFrontendsCommand; @@ -4559,6 +4561,12 @@ public class LogicalPlanBuilder extends DorisParserBaseVisitor<Object> { return new ShowStorageEnginesCommand(); } + @Override + public LogicalPlan visitShowDiagnoseTablet(ShowDiagnoseTabletContext ctx) { + long tabletId = Long.parseLong(ctx.INTEGER_VALUE().getText()); + return new ShowDiagnoseTabletCommand(tabletId); + } + @Override public LogicalPlan visitShowCreateTable(ShowCreateTableContext ctx) { List<String> nameParts = visitMultipartIdentifier(ctx.name); diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java index dced9a0a579..8f474ea395f 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/PlanType.java @@ -202,6 +202,7 @@ public enum PlanType { SHOW_CREATE_TABLE_COMMAND, SHOW_CREATE_VIEW_COMMAND, SHOW_DELETE_COMMAND, + SHOW_DIAGNOSE_TABLET_COMMAND, SHOW_DYNAMIC_PARTITION_COMMAND, SHOW_EVENTS_COMMAND, SHOW_FRONTENDS_COMMAND, diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowDiagnoseTabletCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowDiagnoseTabletCommand.java new file mode 100644 index 00000000000..6dac6ca214e --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowDiagnoseTabletCommand.java @@ -0,0 +1,84 @@ +// 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.analysis.RedirectStatus; +import org.apache.doris.catalog.Column; +import org.apache.doris.catalog.Env; +import org.apache.doris.catalog.ScalarType; +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.Diagnoser; + +import com.google.common.collect.ImmutableList; + +import java.util.List; + +/** + * Represents the command for SHOW TABLET DIAGNOSIS + */ +public class ShowDiagnoseTabletCommand extends ShowCommand { + public static final ImmutableList<String> TITLE_NAMES = new ImmutableList.Builder<String>() + .add("Item").add("Info").add("Suggestion") + .build(); + + private final long tabletId; + + public ShowDiagnoseTabletCommand(long tabletId) { + super(PlanType.SHOW_DIAGNOSE_TABLET_COMMAND); + this.tabletId = tabletId; + } + + public ShowResultSetMetaData getMetaData() { + ShowResultSetMetaData.Builder builder = ShowResultSetMetaData.builder(); + for (String title : TITLE_NAMES) { + builder.addColumn(new Column(title, ScalarType.createVarchar(1024))); + } + return builder.build(); + } + + @Override + public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { + // check auth + if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.ADMIN)) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR, "ADMIN"); + } + + List<List<String>> resultRowSet = Diagnoser.diagnoseTablet(tabletId); + // Set the result set and send it using the executor + return new ShowResultSet(getMetaData(), resultRowSet); + } + + @Override + public <R, C> R accept(PlanVisitor<R, C> visitor, C context) { + return visitor.visitShowDiagnoseTabletCommand(this, context); + } + + @Override + public RedirectStatus toRedirectStatus() { + return RedirectStatus.FORWARD_NO_SYNC; + } + +} diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java index b4a56f71d41..c00c0ef90ca 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/visitor/CommandVisitor.java @@ -81,6 +81,7 @@ import org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand; import org.apache.doris.nereids.trees.plans.commands.ShowCreateTableCommand; import org.apache.doris.nereids.trees.plans.commands.ShowCreateViewCommand; import org.apache.doris.nereids.trees.plans.commands.ShowDeleteCommand; +import org.apache.doris.nereids.trees.plans.commands.ShowDiagnoseTabletCommand; import org.apache.doris.nereids.trees.plans.commands.ShowDynamicPartitionCommand; import org.apache.doris.nereids.trees.plans.commands.ShowEventsCommand; import org.apache.doris.nereids.trees.plans.commands.ShowFrontendsCommand; @@ -433,6 +434,10 @@ public interface CommandVisitor<R, C> { return visitCommand(recoverDatabaseCommand, context); } + default R visitShowDiagnoseTabletCommand(ShowDiagnoseTabletCommand showDiagnoseTabletCommand, C context) { + return visitCommand(showDiagnoseTabletCommand, context); + } + default R visitRecoverTableCommand(RecoverTableCommand recoverTableCommand, C context) { return visitCommand(recoverTableCommand, context); } diff --git a/regression-test/suites/nereids_p0/show/test_show_diagnose_tablet.groovy b/regression-test/suites/nereids_p0/show/test_show_diagnose_tablet.groovy new file mode 100644 index 00000000000..029fac7428e --- /dev/null +++ b/regression-test/suites/nereids_p0/show/test_show_diagnose_tablet.groovy @@ -0,0 +1,39 @@ +// 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_show_diagnose_tablet_nereids", "query,diagnose") { + String tableName = "test_table_for_diagnosis"; + String tabletId = ""; + try { + // Create a new table to test the SHOW TABLET DIAGNOSIS command + sql "CREATE TABLE IF NOT EXISTS ${tableName} (id INT, name STRING) DUPLICATE KEY(id) DISTRIBUTED BY HASH(id) BUCKETS 3 PROPERTIES('replication_num'='1');" + + // Extract tablet ID from the created table + def showTabletsResult = sql "SHOW TABLETS FROM ${tableName}" + assert showTabletsResult.size() > 0 + tabletId = showTabletsResult[0][0] // Assuming the first tablet ID is used + + // Execute the SHOW TABLET DIAGNOSIS command and verify the output + checkNereidsExecute("SHOW TABLET DIAGNOSIS ${tabletId}") + } catch (Exception e) { + log.error("Failed to execute SHOW TABLET DIAGNOSIS command", e) + throw e + } finally { + try_sql("DROP TABLE IF EXISTS ${tableName}") + } +} + --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org