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 b49374d30f3 [Enhancement] (nereids)implement showProcessListCommand in
nereids (#43158)
b49374d30f3 is described below
commit b49374d30f3b515a5e6f86837c7caec7633ebfc5
Author: Sridhar R Manikarnike <[email protected]>
AuthorDate: Mon Dec 2 08:28:19 2024 +0530
[Enhancement] (nereids)implement showProcessListCommand in nereids (#43158)
Issue Number: close #42729
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +-
.../doris/nereids/parser/LogicalPlanBuilder.java | 7 ++
.../apache/doris/nereids/trees/plans/PlanType.java | 1 +
.../plans/commands/ShowProcessListCommand.java | 131 +++++++++++++++++++++
.../trees/plans/visitor/CommandVisitor.java | 5 +
.../show/test_show_process_list_command.groovy | 30 +++++
6 files changed, 175 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 8edcbb40c3c..d30ef144e52 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
@@ -229,6 +229,7 @@ supportedShowStatement
| SHOW PLUGINS
#showPlugins
| SHOW REPOSITORIES
#showRepositories
| SHOW BRIEF? CREATE TABLE name=multipartIdentifier
#showCreateTable
+ | SHOW FULL? PROCESSLIST
#showProcessList
| SHOW ROLES
#showRoles
| SHOW PARTITION partitionId=INTEGER_VALUE
#showPartitionId
| SHOW PRIVILEGES
#showPrivileges
@@ -295,7 +296,6 @@ unsupportedShowStatement
| SHOW TABLE STATUS ((FROM | IN) database=multipartIdentifier)? wildWhere?
#showTableStatus
| SHOW FULL? TABLES ((FROM | IN) database=multipartIdentifier)? wildWhere?
#showTables
| SHOW FULL? VIEWS ((FROM | IN) database=multipartIdentifier)? wildWhere?
#showViews
- | SHOW FULL? PROCESSLIST
#showProcessList
| SHOW (GLOBAL | SESSION | LOCAL)? STATUS wildWhere?
#showStatus
| SHOW CREATE MATERIALIZED VIEW name=multipartIdentifier
#showMaterializedView
| SHOW CREATE (GLOBAL | SESSION | LOCAL)? FUNCTION functionIdentifier
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 60eda00ce89..1422d807b71 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
@@ -248,6 +248,7 @@ import
org.apache.doris.nereids.DorisParser.ShowPluginsContext;
import org.apache.doris.nereids.DorisParser.ShowPrivilegesContext;
import org.apache.doris.nereids.DorisParser.ShowProcContext;
import org.apache.doris.nereids.DorisParser.ShowProcedureStatusContext;
+import org.apache.doris.nereids.DorisParser.ShowProcessListContext;
import org.apache.doris.nereids.DorisParser.ShowReplicaDistributionContext;
import org.apache.doris.nereids.DorisParser.ShowRepositoriesContext;
import org.apache.doris.nereids.DorisParser.ShowRolesContext;
@@ -536,6 +537,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowPluginsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowPrivilegesCommand;
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.ShowProcessListCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowReplicaDistributionCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand;
@@ -4756,6 +4758,11 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
return new ShowTableIdCommand(tableId);
}
+ @Override
+ public LogicalPlan visitShowProcessList(ShowProcessListContext ctx) {
+ return new ShowProcessListCommand(ctx.FULL() != null);
+ }
+
@Override
public LogicalPlan visitSync(SyncContext ctx) {
return new SyncCommand();
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 d07c90b7ccd..177e6b4fcff 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
@@ -212,6 +212,7 @@ public enum PlanType {
SHOW_LAST_INSERT_COMMAND,
SHOW_LOAD_PROFILE_COMMAND,
SHOW_PARTITIONID_COMMAND,
+ SHOW_PROCESSLIST_COMMAND,
SHOW_PROC_COMMAND,
SHOW_PLUGINS_COMMAND,
SHOW_PRIVILEGES_COMMAND,
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowProcessListCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowProcessListCommand.java
new file mode 100644
index 00000000000..fe04d61eab6
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowProcessListCommand.java
@@ -0,0 +1,131 @@
+// 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.PrimitiveType;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.common.ClientPool;
+import org.apache.doris.common.Pair;
+import org.apache.doris.common.proc.FrontendsProcNode;
+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.thrift.FrontendService;
+import org.apache.doris.thrift.TNetworkAddress;
+import org.apache.doris.thrift.TShowProcessListRequest;
+import org.apache.doris.thrift.TShowProcessListResult;
+
+import com.google.common.collect.Lists;
+import org.apache.logging.log4j.LogManager;
+import org.apache.logging.log4j.Logger;
+
+import java.util.List;
+
+/**
+ * Represents the command for SHOW PROCESSLIST
+ */
+public class ShowProcessListCommand extends ShowCommand {
+ private static final Logger LOG =
LogManager.getLogger(ShowProcessListCommand.class);
+ private static final ShowResultSetMetaData PROCESSLIST_META_DATA =
ShowResultSetMetaData.builder()
+ .addColumn(new Column("CurrentConnected",
ScalarType.createVarchar(16)))
+ .addColumn(new Column("Id",
ScalarType.createType(PrimitiveType.BIGINT)))
+ .addColumn(new Column("User", ScalarType.createVarchar(16)))
+ .addColumn(new Column("Host", ScalarType.createVarchar(16)))
+ .addColumn(new Column("LoginTime", ScalarType.createVarchar(16)))
+ .addColumn(new Column("Catalog", ScalarType.createVarchar(16)))
+ .addColumn(new Column("Db", ScalarType.createVarchar(16)))
+ .addColumn(new Column("Command", ScalarType.createVarchar(16)))
+ .addColumn(new Column("Time",
ScalarType.createType(PrimitiveType.INT)))
+ .addColumn(new Column("State", ScalarType.createVarchar(64)))
+ .addColumn(new Column("QueryId", ScalarType.createVarchar(64)))
+ .addColumn(new Column("Info", ScalarType.STRING))
+ .addColumn(new Column("FE", ScalarType.createVarchar(16)))
+ .addColumn(new Column("CloudCluster",
ScalarType.createVarchar(16))).build();
+
+ private final boolean isFull;
+
+ public ShowProcessListCommand(boolean isFull) {
+ super(PlanType.SHOW_PROCESSLIST_COMMAND);
+ this.isFull = isFull;
+ }
+
+ @Override
+ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor)
throws Exception {
+ boolean isShowFullSql = isFull;
+ boolean isShowAllFe =
ConnectContext.get().getSessionVariable().getShowAllFeConnection();
+
+ List<List<String>> rowSet = Lists.newArrayList();
+ List<ConnectContext.ThreadInfo> threadInfos = ctx.getConnectScheduler()
+ .listConnection(ctx.getQualifiedUser(), isShowFullSql);
+ long nowMs = System.currentTimeMillis();
+ for (ConnectContext.ThreadInfo info : threadInfos) {
+ rowSet.add(info.toRow(ctx.getConnectionId(), nowMs));
+ }
+
+ if (isShowAllFe) {
+ try {
+ TShowProcessListRequest request = new
TShowProcessListRequest();
+ request.setShowFullSql(isShowFullSql);
+
request.setCurrentUserIdent(ConnectContext.get().getCurrentUserIdentity().toThrift());
+ List<Pair<String, Integer>> frontends =
FrontendsProcNode.getFrontendWithRpcPort(Env.getCurrentEnv(),
+ false);
+ FrontendService.Client client = null;
+ for (Pair<String, Integer> fe : frontends) {
+ TNetworkAddress thriftAddress = new
TNetworkAddress(fe.key(), fe.value());
+ try {
+ client =
ClientPool.frontendPool.borrowObject(thriftAddress, 3000);
+ } catch (Exception e) {
+ LOG.warn("Failed to get frontend {} client. exception:
{}", fe.key(), e);
+ continue;
+ }
+
+ boolean isReturnToPool = false;
+ try {
+ TShowProcessListResult result =
client.showProcessList(request);
+ if (result.process_list != null &&
result.process_list.size() > 0) {
+ rowSet.addAll(result.process_list);
+ }
+ isReturnToPool = true;
+ } catch (Exception e) {
+ LOG.warn("Failed to request processlist to fe: {} .
exception: {}", fe.key(), e);
+ } finally {
+ if (isReturnToPool) {
+
ClientPool.frontendPool.returnObject(thriftAddress, client);
+ } else {
+
ClientPool.frontendPool.invalidateObject(thriftAddress, client);
+ }
+ }
+ }
+ } catch (Throwable t) {
+ LOG.warn(" fetch process list from other fe failed, ", t);
+ }
+ }
+
+ return new ShowResultSet(PROCESSLIST_META_DATA, rowSet);
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitShowProcessListCommand(this, context);
+ }
+}
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 f3bf05b2377..de5228f4981 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
@@ -95,6 +95,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowPluginsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowPrivilegesCommand;
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.ShowProcessListCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowReplicaDistributionCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRepositoriesCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowRolesCommand;
@@ -529,4 +530,8 @@ public interface CommandVisitor<R, C> {
default R visitCreateRoutineLoadCommand(CreateRoutineLoadCommand
createRoutineLoadCommand, C context) {
return visitCommand(createRoutineLoadCommand, context);
}
+
+ default R visitShowProcessListCommand(ShowProcessListCommand
showProcessListCommand, C context) {
+ return visitCommand(showProcessListCommand, context);
+ }
}
diff --git
a/regression-test/suites/nereids_p0/show/test_show_process_list_command.groovy
b/regression-test/suites/nereids_p0/show/test_show_process_list_command.groovy
new file mode 100644
index 00000000000..b67ab1148c0
--- /dev/null
+++
b/regression-test/suites/nereids_p0/show/test_show_process_list_command.groovy
@@ -0,0 +1,30 @@
+// 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_process_list_command", "query,process_list") {
+ try {
+ // Execute the SHOW PROCESSLIST command and verify the output
+ checkNereidsExecute("SHOW PROCESSLIST")
+
+ // Execute the SHOW FULL PROCESSLIST command and verify the output
+ checkNereidsExecute("SHOW FULL PROCESSLIST")
+ } catch (Exception e) {
+ // Log any exceptions that occur during testing
+ log.error("Failed to execute SHOW PROCESSLIST command", e)
+ throw e
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]