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 a8de28c783a [Enhancement] (nereids)implement showProcCommand in
nereids (#43146)
a8de28c783a is described below
commit a8de28c783aca6ffdaa68e041e149bbc0b0b3750
Author: Vallish Pai <[email protected]>
AuthorDate: Wed Nov 13 12:58:22 2024 +0530
[Enhancement] (nereids)implement showProcCommand in nereids (#43146)
Issue Number: close #42750
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 4 +-
.../doris/nereids/parser/LogicalPlanBuilder.java | 8 ++
.../apache/doris/nereids/trees/plans/PlanType.java | 1 +
.../trees/plans/commands/ShowProcCommand.java | 106 +++++++++++++++++++++
.../trees/plans/visitor/CommandVisitor.java | 5 +
.../nereids_p0/ddl/show/show_proc_nereids.groovy | 22 +++++
6 files changed, 144 insertions(+), 2 deletions(-)
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 4da0078ce1e..8eedc739f28 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
@@ -197,6 +197,7 @@ supportedShowStatement
(FROM |IN) tableName=multipartIdentifier
((FROM | IN) database=identifier)?
#showView
| SHOW ROLES
#showRoles
+ | SHOW PROC path=STRING_LITERAL
#showProc
;
unsupportedOtherStatement
@@ -264,7 +265,6 @@ unsupportedShowStatement
((FROM | IN) database=multipartIdentifier)? wildWhere?
#showColumns
| SHOW COLLATION wildWhere?
#showCollation
| SHOW ((CHAR SET) | CHARSET) wildWhere?
#showCharset
- | SHOW PROC path=STRING_LITERAL
#showProc
| SHOW COUNT LEFT_PAREN ASTERISK RIGHT_PAREN (WARNINGS | ERRORS)
#showWaringErrorCount
| SHOW (WARNINGS | ERRORS) limitClause?
#showWaringErrors
| SHOW LOAD WARNINGS ((((FROM | IN) database=multipartIdentifier)?
@@ -317,7 +317,7 @@ unsupportedShowStatement
| SHOW ENCRYPTKEYS ((FROM | IN) database=multipartIdentifier)? wildWhere?
#showEncryptKeys
| SHOW SYNC JOB ((FROM | IN) database=multipartIdentifier)?
#showSyncJob
| SHOW TABLE CREATION ((FROM | IN) database=multipartIdentifier)?
wildWhere? #showTableCreation
- | SHOW LAST INSERT
#showLastInsert
+ | SHOW LAST INSERT
#showLastInsert
| SHOW CREATE MATERIALIZED VIEW mvName=identifier
ON tableName=multipartIdentifier
#showCreateMaterializedView
| SHOW CATALOG RECYCLE BIN wildWhere?
#showCatalogRecycleBin
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 02cb23e4269..156df4333d5 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
@@ -196,6 +196,7 @@ import
org.apache.doris.nereids.DorisParser.ShowConfigContext;
import org.apache.doris.nereids.DorisParser.ShowConstraintContext;
import org.apache.doris.nereids.DorisParser.ShowCreateMTMVContext;
import org.apache.doris.nereids.DorisParser.ShowCreateProcedureContext;
+import org.apache.doris.nereids.DorisParser.ShowProcContext;
import org.apache.doris.nereids.DorisParser.ShowProcedureStatusContext;
import org.apache.doris.nereids.DorisParser.ShowRolesContext;
import org.apache.doris.nereids.DorisParser.ShowVariablesContext;
@@ -429,6 +430,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowConfigCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowProcCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand;
@@ -4066,4 +4068,10 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
public LogicalPlan visitShowRoles(ShowRolesContext ctx) {
return new ShowRolesCommand();
}
+
+ @Override
+ public LogicalPlan visitShowProc(ShowProcContext ctx) {
+ String path = stripQuotes(ctx.path.getText());
+ return new ShowProcCommand(path);
+ }
}
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 dde7acedecd..b3c402daa9a 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
@@ -176,6 +176,7 @@ public enum PlanType {
PREPARED_COMMAND,
EXECUTE_COMMAND,
SHOW_CONFIG_COMMAND,
+ SHOW_PROC_COMMAND,
SHOW_ROLE_COMMAND,
SHOW_VARIABLES_COMMAND,
SHOW_AUTHORS_COMMAND,
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowProcCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowProcCommand.java
new file mode 100644
index 00000000000..da2fb38c4d8
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowProcCommand.java
@@ -0,0 +1,106 @@
+// 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.AnalysisException;
+import org.apache.doris.common.ErrorCode;
+import org.apache.doris.common.ErrorReport;
+import org.apache.doris.common.proc.ProcNodeInterface;
+import org.apache.doris.common.proc.ProcResult;
+import org.apache.doris.common.proc.ProcService;
+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.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+
+/**
+ * show proc command
+ */
+public class ShowProcCommand extends ShowCommand {
+ public static final Logger LOG =
LogManager.getLogger(ShowProcCommand.class);
+ private final String path;
+
+ /**
+ * constructor
+ */
+ public ShowProcCommand(String path) {
+ super(PlanType.SHOW_PROC_COMMAND);
+ this.path = path;
+ }
+
+ /**
+ * get meta for show proc
+ */
+ public ShowResultSetMetaData getMetaData(ProcNodeInterface procNode) {
+ ShowResultSetMetaData.Builder builder =
ShowResultSetMetaData.builder();
+ ProcResult result = null;
+ try {
+ result = procNode.fetchResult();
+ } catch (AnalysisException e) {
+ return builder.build();
+ }
+
+ for (String col : result.getColumnNames()) {
+ builder.addColumn(new Column(col, ScalarType.createVarchar(30)));
+ }
+ return builder.build();
+ }
+
+ private ShowResultSet handleShowProc(ConnectContext ctx, StmtExecutor
executor) throws Exception {
+ if (!Env.getCurrentEnv().getAccessManager()
+ .checkGlobalPriv(ctx, PrivPredicate.ADMIN_OR_NODE)) {
+
ErrorReport.reportAnalysisException(ErrorCode.ERR_SPECIFIC_ACCESS_DENIED_ERROR,
"ADMIN");
+ }
+
+ ProcNodeInterface procNode = ProcService.getInstance().open(path);
+ List<List<String>> finalRows = procNode.fetchResult().getRows();
+ ShowResultSet resultSet = new ShowResultSet(getMetaData(procNode),
finalRows);
+ return resultSet;
+ }
+
+ @Override
+ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor)
throws Exception {
+ return handleShowProc(ctx, executor);
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitShowProcCommand(this, context);
+ }
+
+ @Override
+ public RedirectStatus toRedirectStatus() {
+ if (ConnectContext.get().getSessionVariable().getForwardToMaster()) {
+ return RedirectStatus.FORWARD_NO_SYNC;
+ } else {
+ return RedirectStatus.NO_FORWARD;
+ }
+ }
+}
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 16e07e83589..7d879a8efdf 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
@@ -52,6 +52,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowConfigCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowConstraintsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowCreateMTMVCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowCreateProcedureCommand;
+import org.apache.doris.nereids.trees.plans.commands.ShowProcCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowProcedureStatusCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowVariablesCommand;
@@ -252,4 +253,8 @@ public interface CommandVisitor<R, C> {
default R visitShowRolesCommand(ShowRolesCommand showRolesCommand, C
context) {
return visitCommand(showRolesCommand, context);
}
+
+ default R visitShowProcCommand(ShowProcCommand showProcCommand, C context)
{
+ return visitCommand(showProcCommand, context);
+ }
}
diff --git
a/regression-test/suites/nereids_p0/ddl/show/show_proc_nereids.groovy
b/regression-test/suites/nereids_p0/ddl/show/show_proc_nereids.groovy
new file mode 100644
index 00000000000..7872835ed9b
--- /dev/null
+++ b/regression-test/suites/nereids_p0/ddl/show/show_proc_nereids.groovy
@@ -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_proc_nereids") {
+ // can not use qt command since the output change based on cluster and
backend ip
+ checkNereidsExecute("""show proc '/diagnose/cluster_balance';""")
+ checkNereidsExecute("""show proc '/backends';""")
+}
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]