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 a7d61489db2 [Enhancement] (nereids) implement
drop/killAnalyzeJobCommand in nereids (#48942)
a7d61489db2 is described below
commit a7d61489db229d0a4e1c4aa9d8c286e563ad31c6
Author: yaoxiao <[email protected]>
AuthorDate: Thu Mar 27 15:11:32 2025 +0800
[Enhancement] (nereids) implement drop/killAnalyzeJobCommand in nereids
(#48942)
Issue Number: close #42712,#42713
---
.../antlr4/org/apache/doris/nereids/DorisParser.g4 | 6 +--
.../doris/nereids/parser/LogicalPlanBuilder.java | 14 ++++++
.../apache/doris/nereids/trees/plans/PlanType.java | 4 +-
.../plans/commands/DropAnalyzeJobCommand.java | 55 +++++++++++++++++++++
.../plans/commands/KillAnalyzeJobCommand.java | 56 ++++++++++++++++++++++
.../nereids/trees/plans/commands/KillCommand.java | 44 +++++++++++++++++
.../trees/plans/visitor/CommandVisitor.java | 10 ++++
.../apache/doris/statistics/AnalysisManager.java | 32 +++++++++++++
.../suites/statistics/test_drop_analyze_job.groovy | 53 ++++++++++++++++++++
9 files changed, 270 insertions(+), 4 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 4a7be12468d..2c806bc996c 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
@@ -745,15 +745,15 @@ supportedStatsStatement
columns=identifierList? partitionSpec?
#dropStats
| DROP CACHED STATS tableName=multipartIdentifier
#dropCachedStats
| DROP EXPIRED STATS
#dropExpiredStats
+ | KILL ANALYZE jobId=INTEGER_VALUE
#killAnalyzeJob
+ | DROP ANALYZE JOB INTEGER_VALUE
#dropAnalyzeJob
| SHOW TABLE STATS tableName=multipartIdentifier
partitionSpec? columnList=identifierList?
#showTableStats
| SHOW TABLE STATS tableId=INTEGER_VALUE
#showTableStats
;
unsupportedStatsStatement
- : DROP ANALYZE JOB INTEGER_VALUE
#dropAanalyzeJob
- | KILL ANALYZE jobId=INTEGER_VALUE
#killAnalyzeJob
- | SHOW COLUMN CACHED? STATS tableName=multipartIdentifier
+ : SHOW COLUMN CACHED? STATS tableName=multipartIdentifier
columnList=identifierList? partitionSpec?
#showColumnStats
| SHOW ANALYZE TASK STATUS jobId=INTEGER_VALUE
#showAnalyzeTask
;
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 6d6341c7246..d17988c8b19 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
@@ -565,6 +565,7 @@ import
org.apache.doris.nereids.trees.plans.commands.CreateWorkloadGroupCommand;
import org.apache.doris.nereids.trees.plans.commands.DeleteFromCommand;
import org.apache.doris.nereids.trees.plans.commands.DeleteFromUsingCommand;
import org.apache.doris.nereids.trees.plans.commands.DescribeCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropAnalyzeJobCommand;
import org.apache.doris.nereids.trees.plans.commands.DropCachedStatsCommand;
import org.apache.doris.nereids.trees.plans.commands.DropCatalogCommand;
import
org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand;
@@ -591,6 +592,7 @@ import
org.apache.doris.nereids.trees.plans.commands.ExplainCommand;
import
org.apache.doris.nereids.trees.plans.commands.ExplainCommand.ExplainLevel;
import org.apache.doris.nereids.trees.plans.commands.ExportCommand;
import org.apache.doris.nereids.trees.plans.commands.HelpCommand;
+import org.apache.doris.nereids.trees.plans.commands.KillAnalyzeJobCommand;
import org.apache.doris.nereids.trees.plans.commands.LoadCommand;
import org.apache.doris.nereids.trees.plans.commands.PauseJobCommand;
import org.apache.doris.nereids.trees.plans.commands.PauseMTMVCommand;
@@ -6365,5 +6367,17 @@ public class LogicalPlanBuilder extends
DorisParserBaseVisitor<Object> {
columnName,
properties);
}
+
+ @Override
+ public LogicalPlan visitDropAnalyzeJob(DorisParser.DropAnalyzeJobContext
ctx) {
+ long jobId = Long.parseLong(ctx.INTEGER_VALUE().getText());
+ return new DropAnalyzeJobCommand(jobId);
+ }
+
+ @Override
+ public LogicalPlan visitKillAnalyzeJob(DorisParser.KillAnalyzeJobContext
ctx) {
+ long jobId = Long.parseLong(ctx.jobId.getText());
+ return new KillAnalyzeJobCommand(jobId);
+ }
}
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 048a4cb2e7d..67a5341b055 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
@@ -325,5 +325,7 @@ public enum PlanType {
DROP_CACHED_STATS_COMMAND,
DROP_EXPIRED_STATS_COMMAND,
ALTER_TABLE_STATS_COMMAND,
- ALTER_COLUMN_STATS_COMMAND
+ ALTER_COLUMN_STATS_COMMAND,
+ KILL_ANALYZE_JOB_COMMAND,
+ DROP_ANALYZE_JOB_COMMAND
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommand.java
new file mode 100644
index 00000000000..402e5c55750
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommand.java
@@ -0,0 +1,55 @@
+// 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.StmtType;
+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.StmtExecutor;
+
+/**
+ * DROP ANALYZE JOB [JOB_ID]
+ */
+public class DropAnalyzeJobCommand extends DropCommand {
+ private final long jobId;
+
+ public DropAnalyzeJobCommand(long jobId) {
+ super(PlanType.DROP_ANALYZE_JOB_COMMAND);
+ this.jobId = jobId;
+ }
+
+ public long getJobId() {
+ return jobId;
+ }
+
+ @Override
+ public void doRun(ConnectContext ctx, StmtExecutor executor) throws
Exception {
+ ctx.getEnv().getAnalysisManager().dropAnalyzeJob(this);
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitDropAnalyzeJobCommand(this, context);
+ }
+
+ @Override
+ public StmtType stmtType() {
+ return StmtType.DROP;
+ }
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommand.java
new file mode 100644
index 00000000000..3c363cba9b2
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommand.java
@@ -0,0 +1,56 @@
+// 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.StmtType;
+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.StmtExecutor;
+
+/**
+ * KillAnalyzeJobCommand
+ */
+public class KillAnalyzeJobCommand extends KillCommand {
+
+ private final long jobId;
+
+ public KillAnalyzeJobCommand(long jobId) {
+ super(PlanType.KILL_ANALYZE_JOB_COMMAND);
+ this.jobId = jobId;
+ }
+
+ public long getJobId() {
+ return jobId;
+ }
+
+ @Override
+ public void doRun(ConnectContext ctx, StmtExecutor executor) throws
Exception {
+ ctx.getEnv().getAnalysisManager().handleKillAnalyzeJob(this);
+ }
+
+ @Override
+ public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
+ return visitor.visitKillAnalyzeJobCommand(this, context);
+ }
+
+ @Override
+ public StmtType stmtType() {
+ return StmtType.KILL;
+ }
+}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillCommand.java
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillCommand.java
new file mode 100644
index 00000000000..3b3bec93ea4
--- /dev/null
+++
b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillCommand.java
@@ -0,0 +1,44 @@
+// 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.StmtType;
+import org.apache.doris.nereids.trees.plans.PlanType;
+import org.apache.doris.qe.ConnectContext;
+import org.apache.doris.qe.StmtExecutor;
+
+/**
+ * base class for all kill commands
+ */
+public abstract class KillCommand extends Command implements ForwardWithSync {
+ public KillCommand(PlanType type) {
+ super(type);
+ }
+
+ @Override
+ public StmtType stmtType() {
+ return StmtType.KILL;
+ }
+
+ @Override
+ public void run(ConnectContext ctx, StmtExecutor executor) throws
Exception {
+ doRun(ctx, executor);
+ }
+
+ public abstract void doRun(ConnectContext ctx, StmtExecutor executor)
throws Exception;
+}
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 958ea039071..4bdac8127bd 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
@@ -64,6 +64,7 @@ import
org.apache.doris.nereids.trees.plans.commands.CreateWorkloadGroupCommand;
import org.apache.doris.nereids.trees.plans.commands.DeleteFromCommand;
import org.apache.doris.nereids.trees.plans.commands.DeleteFromUsingCommand;
import org.apache.doris.nereids.trees.plans.commands.DescribeCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropAnalyzeJobCommand;
import org.apache.doris.nereids.trees.plans.commands.DropCachedStatsCommand;
import org.apache.doris.nereids.trees.plans.commands.DropCatalogCommand;
import
org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand;
@@ -88,6 +89,7 @@ import
org.apache.doris.nereids.trees.plans.commands.DropWorkloadPolicyCommand;
import org.apache.doris.nereids.trees.plans.commands.ExplainCommand;
import org.apache.doris.nereids.trees.plans.commands.ExportCommand;
import org.apache.doris.nereids.trees.plans.commands.HelpCommand;
+import org.apache.doris.nereids.trees.plans.commands.KillAnalyzeJobCommand;
import org.apache.doris.nereids.trees.plans.commands.LoadCommand;
import org.apache.doris.nereids.trees.plans.commands.PauseJobCommand;
import org.apache.doris.nereids.trees.plans.commands.PauseMTMVCommand;
@@ -904,4 +906,12 @@ public interface CommandVisitor<R, C> {
default R visitAlterColumnStatsCommand(AlterColumnStatsCommand
alterColumnStatsCommand, C context) {
return visitCommand(alterColumnStatsCommand, context);
}
+
+ default R visitKillAnalyzeJobCommand(KillAnalyzeJobCommand
killAnalyzeJobCommand, C context) {
+ return visitCommand(killAnalyzeJobCommand, context);
+ }
+
+ default R visitDropAnalyzeJobCommand(DropAnalyzeJobCommand
dropAnalyzeJobCommand, C context) {
+ return visitCommand(dropAnalyzeJobCommand, context);
+ }
}
diff --git
a/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java
b/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java
index d04120b3af7..c43adeccc41 100644
--- a/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java
+++ b/fe/fe-core/src/main/java/org/apache/doris/statistics/AnalysisManager.java
@@ -60,7 +60,9 @@ import
org.apache.doris.nereids.trees.expressions.SlotReference;
import org.apache.doris.nereids.trees.plans.commands.AnalyzeCommand;
import org.apache.doris.nereids.trees.plans.commands.AnalyzeDatabaseCommand;
import org.apache.doris.nereids.trees.plans.commands.AnalyzeTableCommand;
+import org.apache.doris.nereids.trees.plans.commands.DropAnalyzeJobCommand;
import org.apache.doris.nereids.trees.plans.commands.DropStatsCommand;
+import org.apache.doris.nereids.trees.plans.commands.KillAnalyzeJobCommand;
import org.apache.doris.nereids.trees.plans.commands.info.PartitionNamesInfo;
import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo;
import org.apache.doris.persist.AnalyzeDeletionLog;
@@ -1166,6 +1168,23 @@ public class AnalysisManager implements Writable {
}
}
+ public void handleKillAnalyzeJob(KillAnalyzeJobCommand
killAnalyzeJobCommand) throws DdlException {
+ Map<Long, BaseAnalysisTask> analysisTaskMap =
analysisJobIdToTaskMap.remove(killAnalyzeJobCommand.getJobId());
+ if (analysisTaskMap == null) {
+ throw new DdlException("Job not exists or already finished");
+ }
+ BaseAnalysisTask anyTask =
analysisTaskMap.values().stream().findFirst().orElse(null);
+ if (anyTask == null) {
+ return;
+ }
+ checkPriv(anyTask);
+ logKilled(analysisJobInfoMap.get(anyTask.getJobId()));
+ for (BaseAnalysisTask taskInfo : analysisTaskMap.values()) {
+ taskInfo.cancel();
+ logKilled(taskInfo.info);
+ }
+ }
+
public void handleKillAnalyzeStmt(KillAnalysisJobStmt killAnalysisJobStmt)
throws DdlException {
Map<Long, BaseAnalysisTask> analysisTaskMap =
analysisJobIdToTaskMap.remove(killAnalysisJobStmt.jobId);
if (analysisTaskMap == null) {
@@ -1335,6 +1354,19 @@ public class AnalysisManager implements Writable {
}
}
+ public void dropAnalyzeJob(DropAnalyzeJobCommand analyzeJobCommand) throws
DdlException {
+ AnalysisInfo jobInfo =
analysisJobInfoMap.get(analyzeJobCommand.getJobId());
+ if (jobInfo == null) {
+ throw new DdlException(String.format("Analyze job [%d] not
exists", analyzeJobCommand.getJobId()));
+ }
+ checkPriv(jobInfo);
+ long jobId = analyzeJobCommand.getJobId();
+ AnalyzeDeletionLog analyzeDeletionLog = new AnalyzeDeletionLog(jobId);
+
Env.getCurrentEnv().getEditLog().logDeleteAnalysisJob(analyzeDeletionLog);
+ replayDeleteAnalysisJob(analyzeDeletionLog);
+ removeAll(findTasks(jobId));
+ }
+
public void dropAnalyzeJob(DropAnalyzeJobStmt analyzeJobStmt) throws
DdlException {
AnalysisInfo jobInfo =
analysisJobInfoMap.get(analyzeJobStmt.getJobId());
if (jobInfo == null) {
diff --git a/regression-test/suites/statistics/test_drop_analyze_job.groovy
b/regression-test/suites/statistics/test_drop_analyze_job.groovy
new file mode 100644
index 00000000000..f77509ac165
--- /dev/null
+++ b/regression-test/suites/statistics/test_drop_analyze_job.groovy
@@ -0,0 +1,53 @@
+// 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_drop_analyze_job") {
+
+ sql """drop database if exists test_drop_analyze_job"""
+ sql """create database test_drop_analyze_job"""
+ sql """use test_drop_analyze_job"""
+
+ sql """CREATE TABLE drop_analyze_job_test (
+ key1 int NOT NULL,
+ value1 varchar(25) NOT NULL,
+ value2 varchar(125) NOT NULL
+ )ENGINE=OLAP
+ DUPLICATE KEY(`key1`)
+ COMMENT "OLAP"
+ DISTRIBUTED BY HASH(`key1`) BUCKETS 2
+ PROPERTIES (
+ "replication_num" = "1"
+ )
+ """
+
+ sql """insert into drop_analyze_job_test values (1, "1", "1")"""
+ sql """analyze table drop_analyze_job_test"""
+
+ def result = sql """show analyze drop_analyze_job_test"""
+ assertEquals(1, result.size())
+
+ result = sql """show analyze drop_analyze_job_test"""
+ jobId0 = result[0][0]
+
+ sql """drop analyze job ${jobId0}"""
+
+ result = sql """show analyze drop_analyze_job_test"""
+ assertEquals(0, result.size())
+
+ sql """drop database if exists test_drop_analyze_jobs"""
+}
+
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]