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 20cd1e1c2bb [Enhancement] (nereids) implement showWarmUpCommand in
nereids (#51081)
20cd1e1c2bb is described below
commit 20cd1e1c2bb762aa5ad2d220ce8985651c3950b8
Author: yaoxiao <[email protected]>
AuthorDate: Wed May 28 09:41:31 2025 +0800
[Enhancement] (nereids) implement showWarmUpCommand in nereids (#51081)
Issue Number: [#51012](https://github.com/apache/doris/issues/51012)
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +-
.../doris/nereids/parser/LogicalPlanBuilder.java | 10 ++
.../apache/doris/nereids/trees/plans/PlanType.java | 1 +
.../trees/plans/commands/ShowWarmUpCommand.java | 131 +++++++++++++++++++++
.../trees/plans/visitor/CommandVisitor.java | 5 +
.../plans/commands/ShowWarmUpCommandTest.java | 51 ++++++++
6 files changed, 199 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 79e42b48b51..a703967cd70 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
@@ -406,6 +406,7 @@ supportedShowStatement
whereClause? sortClause? limitClause?
#showCopy
| SHOW QUERY STATS ((FOR database=identifier)
| (FROM tableName=multipartIdentifier (ALL VERBOSE?)?))?
#showQueryStats
+ | SHOW WARM UP JOB wildWhere?
#showWarmUpJob
;
supportedLoadStatement
@@ -484,7 +485,6 @@ unsupportedShowStatement
| SHOW BUILD INDEX ((FROM | IN) database=multipartIdentifier)?
wildWhere? sortClause? limitClause?
#showBuildIndex
| SHOW REPLICA STATUS FROM baseTableRef wildWhere?
#showReplicaStatus
- | SHOW WARM UP JOB wildWhere?
#showWarmUpJob
;
createRoutineLoad
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 029207c458c..4a64f58d0d0 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
@@ -759,6 +759,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowTriggersCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowUserPropertyCommand;
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.ShowWarmUpCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowWarningErrorCountCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowWarningErrorsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowWhiteListCommand;
@@ -7760,6 +7761,15 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
return new RefreshDictionaryCommand(dbName, dictName);
}
+ @Override
+ public LogicalPlan visitShowWarmUpJob(DorisParser.ShowWarmUpJobContext
ctx) {
+ Expression whereClause = null;
+ if (ctx.wildWhere() != null) {
+ whereClause = getWildWhere(ctx.wildWhere());
+ }
+ return new ShowWarmUpCommand(whereClause);
+ }
+
@Override
public LogicalPlan
visitShowWorkloadGroups(DorisParser.ShowWorkloadGroupsContext ctx) {
String likePattern = null;
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 9c8ffccd501..c86e6148e1e 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
@@ -396,5 +396,6 @@ public enum PlanType {
GRANT_RESOURCE_PRIVILEGE_COMMAND,
GRANT_TABLE_PRIVILEGE_COMMAND,
REVOKE_ROLE_COMMAND,
+ SHOW_WARM_UP_COMMAND,
REVOKE_RESOURCE_PRIVILEGE_COMMAND
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowWarmUpCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowWarmUpCommand.java
new file mode 100644
index 00000000000..92bad56c63e
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/ShowWarmUpCommand.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.analysis.RedirectStatus;
+import org.apache.doris.catalog.Column;
+import org.apache.doris.catalog.Env;
+import org.apache.doris.catalog.ScalarType;
+import org.apache.doris.cloud.catalog.CloudEnv;
+import org.apache.doris.common.AnalysisException;
+import org.apache.doris.nereids.analyzer.UnboundSlot;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+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 com.google.common.collect.ImmutableList;
+
+/**
+ * ShowWarmUpCommand
+ */
+public class ShowWarmUpCommand extends ShowCommand {
+ private static final ImmutableList<String> WARM_UP_JOB_TITLE_NAMES = new
ImmutableList.Builder<String>()
+ .add("JobId")
+ .add("ComputeGroup")
+ .add("Status")
+ .add("Type")
+ .add("CreateTime")
+ .add("FinishBatch")
+ .add("AllBatch")
+ .add("FinishTime")
+ .add("ErrMsg")
+ .build();
+ private Expression whereClause;
+ private boolean showAllJobs = false;
+ private long jobId = -1;
+
+ public ShowWarmUpCommand(Expression whereClause) {
+ super(PlanType.SHOW_WARM_UP_COMMAND);
+ this.whereClause = whereClause;
+ }
+
+ @Override
+ public ShowResultSet doRun(ConnectContext ctx, StmtExecutor executor)
throws Exception {
+ validate();
+ return handleShowCloudWarmUpJob();
+ }
+
+ private ShowResultSet handleShowCloudWarmUpJob() throws AnalysisException {
+ if (showAllJobs) {
+ int limit = ((CloudEnv)
Env.getCurrentEnv()).getCacheHotspotMgr().MAX_SHOW_ENTRIES;
+ return new ShowResultSet(getMetaData(),
+ ((CloudEnv)
Env.getCurrentEnv()).getCacheHotspotMgr().getAllJobInfos(limit));
+ } else {
+ return new ShowResultSet(getMetaData(),
+ ((CloudEnv)
Env.getCurrentEnv()).getCacheHotspotMgr().getSingleJobInfo(jobId));
+ }
+ }
+
+ /**
+ * validate
+ */
+ public void validate() throws AnalysisException {
+ if (whereClause == null) {
+ showAllJobs = true;
+ return;
+ }
+
+ if (!isWhereClauseValid(whereClause)) {
+ throw new AnalysisException("Where clause should looks like one of
them: id = 123");
+ }
+ }
+
+ private boolean isWhereClauseValid(Expression expr) {
+ if (!(expr instanceof EqualTo)) {
+ return false;
+ }
+
+ // left child
+ if (!(expr.child(0) instanceof UnboundSlot)) {
+ return false;
+ }
+
+ String leftKey = ((UnboundSlot) expr.child(0)).getName();
+ if (leftKey.equalsIgnoreCase("id") && (expr.child(1) instanceof
IntegerLiteral)) {
+ jobId = ((IntegerLiteral) expr.child(1)).getLongValue();
+ return true;
+ } else {
+ return false;
+ }
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitShowWarmupCommand(this, context);
+ }
+
+ @Override
+ public ShowResultSetMetaData getMetaData() {
+ ShowResultSetMetaData.Builder builder =
ShowResultSetMetaData.builder();
+ for (String title : WARM_UP_JOB_TITLE_NAMES) {
+ builder.addColumn(new Column(title, ScalarType.createVarchar(30)));
+ }
+ return builder.build();
+ }
+
+ @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 eb0895faed9..8fc696beca9 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
@@ -218,6 +218,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ShowTriggersCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowUserPropertyCommand;
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.ShowWarmUpCommand;
import
org.apache.doris.nereids.trees.plans.commands.ShowWarningErrorCountCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowWarningErrorsCommand;
import org.apache.doris.nereids.trees.plans.commands.ShowWhiteListCommand;
@@ -1213,6 +1214,10 @@ public interface CommandVisitor<R, C> {
return visitCommand(revokeRoleCommand, context);
}
+ default R visitShowWarmupCommand(ShowWarmUpCommand showWarmUpCommand, C
context) {
+ return visitCommand(showWarmUpCommand, context);
+ }
+
default R
visitRevokeResourcePrivilegeCommand(RevokeResourcePrivilegeCommand command, C
context) {
return visitCommand(command, context);
}
diff --git
a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowWarmUpCommandTest.java
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowWarmUpCommandTest.java
new file mode 100644
index 00000000000..591d96dca7c
--- /dev/null
+++
b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/ShowWarmUpCommandTest.java
@@ -0,0 +1,51 @@
+// 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.common.AnalysisException;
+import org.apache.doris.nereids.analyzer.UnboundSlot;
+import org.apache.doris.nereids.trees.expressions.EqualTo;
+import org.apache.doris.nereids.trees.expressions.Expression;
+import org.apache.doris.nereids.trees.expressions.literal.IntegerLiteral;
+import org.apache.doris.nereids.trees.expressions.literal.StringLiteral;
+
+import com.google.common.collect.Lists;
+import org.junit.jupiter.api.Assertions;
+import org.junit.jupiter.api.Test;
+
+public class ShowWarmUpCommandTest {
+
+ @Test
+ public void testValidate() {
+ //test whereClause ia null
+ ShowWarmUpCommand command = new ShowWarmUpCommand(null);
+ Assertions.assertDoesNotThrow(() -> command.validate());
+
+ //test whereClause is equalTo
+ Expression where = new EqualTo(new
UnboundSlot(Lists.newArrayList("test")),
+ new StringLiteral("test"));
+ ShowWarmUpCommand command2 = new ShowWarmUpCommand(where);
+ Assertions.assertThrows(AnalysisException.class, () ->
command2.validate());
+
+ //test whereClause is equalTo
+ Expression where2 = new EqualTo(new
UnboundSlot(Lists.newArrayList("id")),
+ new IntegerLiteral(111));
+ ShowWarmUpCommand command3 = new ShowWarmUpCommand(where2);
+ Assertions.assertDoesNotThrow(() -> command3.validate());
+ }
+}
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]