From d65ee079d2b5b402cf03254ce88be89930d3828e Mon Sep 17 00:00:00 2001 From: yx-keith Date: Tue, 11 Mar 2025 15:00:29 +0800 Subject: [PATCH 01/11] implement dropAnalyzeJobCommand and killAnalyzeJobCommand in nereids --- .../org/apache/doris/nereids/DorisParser.g4 | 4 +- .../nereids/parser/LogicalPlanBuilder.java | 12 ++++ .../doris/nereids/trees/plans/PlanType.java | 4 +- .../plans/commands/DropAnalyzeJobCommand.java | 55 ++++++++++++++++++ .../plans/commands/KillAnalyzeJobCommand.java | 56 +++++++++++++++++++ .../trees/plans/commands/KillCommand.java | 44 +++++++++++++++ .../trees/plans/visitor/CommandVisitor.java | 10 ++++ .../doris/statistics/AnalysisManager.java | 32 +++++++++++ 8 files changed, 214 insertions(+), 3 deletions(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommand.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommand.java create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/KillCommand.java 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 fe76b0f24533c5..255b17eade55d0 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 @@ -742,6 +742,8 @@ supportedStatsStatement | ALTER TABLE name=multipartIdentifier (INDEX indexName=identifier)? MODIFY COLUMN columnName=identifier SET STATS LEFT_PAREN propertyItemList RIGHT_PAREN partitionSpec? #alterColumnStats + | KILL ANALYZE jobId=INTEGER_VALUE #killAnalyzeJob + | DROP ANALYZE JOB INTEGER_VALUE #dropAnalyzeJob ; unsupportedStatsStatement @@ -749,8 +751,6 @@ unsupportedStatsStatement columns=identifierList? partitionSpec? #dropStats | DROP CACHED STATS tableName=multipartIdentifier #dropCachedStats | DROP EXPIRED STATS #dropExpiredStats - | DROP ANALYZE JOB INTEGER_VALUE #dropAanalyzeJob - | KILL ANALYZE jobId=INTEGER_VALUE #killAnalyzeJob | SHOW TABLE STATS tableName=multipartIdentifier partitionSpec? columnList=identifierList? #showTableStats | SHOW TABLE STATS tableId=INTEGER_VALUE #showTableStats 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 49cba1194f5ce6..037003aeb50d9f 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 @@ -562,6 +562,7 @@ 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.DropCatalogCommand; import org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand; import org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand.IdType; @@ -585,6 +586,7 @@ 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; @@ -6159,5 +6161,15 @@ public LogicalPlan visitAlterColumnStats(DorisParser.AlterColumnStatsContext ctx columnName, properties); } + + public LogicalPlan visitKillAnalyzeJob(DorisParser.KillAnalyzeJobContext ctx) { + long jobId = Long.parseLong(ctx.jobId.getText()); + return new KillAnalyzeJobCommand(jobId); + } + + public LogicalPlan visitDropAnalyzeJob(DorisParser.DropAnalyzeJobContext ctx) { + long jobId = Long.parseLong(ctx.INTEGER_VALUE().getText()); + return new DropAnalyzeJobCommand(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 62476ee5030dfc..e16b8950a3401b 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 @@ -313,5 +313,7 @@ public enum PlanType { ALTER_SYSTEM_MODIFY_FRONTEND_OR_BACKEND_HOSTNAME, ALTER_SYSTEM_RENAME_COMPUTE_GROUP, 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 00000000000000..402e5c55750983 --- /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 accept(PlanVisitor 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 00000000000000..3c363cba9b2cda --- /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 accept(PlanVisitor 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 00000000000000..3b3bec93ea43c8 --- /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 fe696fa603cbf5..0f4c9af8859a9f 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.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.DropCatalogCommand; import org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand; import org.apache.doris.nereids.trees.plans.commands.DropConstraintCommand; @@ -85,6 +86,7 @@ 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; @@ -849,4 +851,12 @@ default R visitAlterTableStatsCommand(AlterTableStatsCommand alterTableStatsComm 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 af33c722c661fb..130b5eb0f0ddf8 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,6 +60,8 @@ 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.KillAnalyzeJobCommand; import org.apache.doris.nereids.trees.plans.commands.info.TableNameInfo; import org.apache.doris.persist.AnalyzeDeletionLog; import org.apache.doris.persist.TableStatsDeletionLog; @@ -1142,6 +1144,23 @@ public void updateRemotePartitionStats(long catalogId, long dbId, long tableId, } } + public void handleKillAnalyzeJob(KillAnalyzeJobCommand killAnalyzeJobCommand) throws DdlException { + Map 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 analysisTaskMap = analysisJobIdToTaskMap.remove(killAnalysisJobStmt.jobId); if (analysisTaskMap == null) { @@ -1311,6 +1330,19 @@ public void removeAll(List analysisInfos) { } } + 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) { From 37b42e593b282d356163a9a36d953218a9be1940 Mon Sep 17 00:00:00 2001 From: yx-keith Date: Sat, 22 Mar 2025 14:38:17 +0800 Subject: [PATCH 02/11] add UT for drop/killAnalyzeJobCommand --- .../plans/commands/DropAnalyzeJobCommand.java | 13 ++ .../plans/commands/KillAnalyzeJobCommand.java | 13 ++ .../commands/DropAnalyzeJobCommandTest.java | 110 +++++++++++++++++ .../commands/KillAnalyzeJobCommandTest.java | 111 ++++++++++++++++++ 4 files changed, 247 insertions(+) create mode 100644 fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java create mode 100644 fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java 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 index 402e5c55750983..0e8709507ffe21 100644 --- 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 @@ -18,6 +18,11 @@ package org.apache.doris.nereids.trees.plans.commands; import org.apache.doris.analysis.StmtType; +import org.apache.doris.catalog.Env; +import org.apache.doris.common.AnalysisException; +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; @@ -40,9 +45,17 @@ public long getJobId() { @Override public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { + validate(); ctx.getEnv().getAnalysisManager().dropAnalyzeJob(this); } + public void validate() throws AnalysisException { + if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.DROP)) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, "Permission denied", + ConnectContext.get().getQualifiedUser(), ConnectContext.get().getRemoteIP()); + } + } + @Override public R accept(PlanVisitor visitor, C context) { return visitor.visitDropAnalyzeJobCommand(this, context); 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 index 3c363cba9b2cda..0f937850caa3e3 100644 --- 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 @@ -18,6 +18,11 @@ package org.apache.doris.nereids.trees.plans.commands; import org.apache.doris.analysis.StmtType; +import org.apache.doris.catalog.Env; +import org.apache.doris.common.AnalysisException; +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; @@ -41,9 +46,17 @@ public long getJobId() { @Override public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { + validate(); ctx.getEnv().getAnalysisManager().handleKillAnalyzeJob(this); } + public void validate() throws AnalysisException { + if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.DROP)) { + ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, "Permission denied", + ConnectContext.get().getQualifiedUser(), ConnectContext.get().getRemoteIP()); + } + } + @Override public R accept(PlanVisitor visitor, C context) { return visitor.visitKillAnalyzeJobCommand(this, context); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java new file mode 100644 index 00000000000000..430d4a1cb793e2 --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java @@ -0,0 +1,110 @@ +// 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.backup.CatalogMocker; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.Env; +import org.apache.doris.common.AnalysisException; +import org.apache.doris.datasource.InternalCatalog; +import org.apache.doris.mysql.privilege.AccessControllerManager; +import org.apache.doris.mysql.privilege.PrivPredicate; +import org.apache.doris.qe.ConnectContext; + +import mockit.Expectations; +import mockit.Mocked; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class DropAnalyzeJobCommandTest { + private static final String internalCtl = InternalCatalog.INTERNAL_CATALOG_NAME; + @Mocked + private Env env; + @Mocked + private InternalCatalog catalog; + @Mocked + private AccessControllerManager accessControllerManager; + @Mocked + private ConnectContext connectContext; + private Database db; + + private void runBefore() throws Exception { + db = CatalogMocker.mockDb(); + new Expectations() { + { + Env.getCurrentEnv(); + minTimes = 0; + result = env; + + env.getCatalogMgr().getCatalog(anyString); + minTimes = 0; + result = catalog; + + catalog.getDb(anyString); + minTimes = 0; + result = db; + + env.getAccessManager(); + minTimes = 0; + result = accessControllerManager; + + ConnectContext.get(); + minTimes = 0; + result = connectContext; + + connectContext.isSkipAuth(); + minTimes = 0; + result = true; + + accessControllerManager.checkGlobalPriv(connectContext, PrivPredicate.DROP); + minTimes = 0; + result = true; + } + }; + } + + @Test + public void testValidateNormal() throws Exception { + runBefore(); + DropAnalyzeJobCommand command = new DropAnalyzeJobCommand(10000); + Assertions.assertDoesNotThrow(() -> command.validate()); + } + + @Test + void testValidateNoPrivilege() { + new Expectations() { + { + Env.getCurrentEnv(); + minTimes = 0; + result = env; + + env.getAccessManager(); + minTimes = 0; + result = accessControllerManager; + + accessControllerManager.checkGlobalPriv(connectContext, PrivPredicate.DROP); + minTimes = 0; + result = false; + } + }; + + DropAnalyzeJobCommand command = new DropAnalyzeJobCommand(10000); + Assertions.assertThrows(AnalysisException.class, () -> command.validate(), + "Permission denied command denied to user 'null'@'null' for table 'null'"); + } +} diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java new file mode 100644 index 00000000000000..0216d52483cafe --- /dev/null +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java @@ -0,0 +1,111 @@ +// 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.backup.CatalogMocker; +import org.apache.doris.catalog.Database; +import org.apache.doris.catalog.Env; +import org.apache.doris.common.AnalysisException; +import org.apache.doris.datasource.InternalCatalog; +import org.apache.doris.mysql.privilege.AccessControllerManager; +import org.apache.doris.mysql.privilege.PrivPredicate; +import org.apache.doris.qe.ConnectContext; + +import mockit.Expectations; +import mockit.Mocked; +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +public class KillAnalyzeJobCommandTest { + private static final String internalCtl = InternalCatalog.INTERNAL_CATALOG_NAME; + @Mocked + private Env env; + @Mocked + private InternalCatalog catalog; + @Mocked + private AccessControllerManager accessControllerManager; + @Mocked + private ConnectContext connectContext; + private Database db; + + private void runBefore() throws Exception { + db = CatalogMocker.mockDb(); + new Expectations() { + { + Env.getCurrentEnv(); + minTimes = 0; + result = env; + + env.getCatalogMgr().getCatalog(anyString); + minTimes = 0; + result = catalog; + + catalog.getDb(anyString); + minTimes = 0; + result = db; + + env.getAccessManager(); + minTimes = 0; + result = accessControllerManager; + + ConnectContext.get(); + minTimes = 0; + result = connectContext; + + connectContext.isSkipAuth(); + minTimes = 0; + result = true; + + accessControllerManager.checkGlobalPriv(connectContext, PrivPredicate.DROP); + minTimes = 0; + result = true; + } + }; + } + + @Test + public void testValidateNormal() throws Exception { + runBefore(); + KillAnalyzeJobCommand command = new KillAnalyzeJobCommand(10000); + Assertions.assertDoesNotThrow(() -> command.validate()); + } + + @Test + void testValidateNoPrivilege() { + new Expectations() { + { + Env.getCurrentEnv(); + minTimes = 0; + result = env; + + env.getAccessManager(); + minTimes = 0; + result = accessControllerManager; + + accessControllerManager.checkGlobalPriv(connectContext, PrivPredicate.DROP); + minTimes = 0; + result = false; + } + }; + + KillAnalyzeJobCommand command = new KillAnalyzeJobCommand(10000); + Assertions.assertThrows(AnalysisException.class, () -> command.validate(), + "Permission denied command denied to user 'null'@'null' for table 'null'"); + } + +} From 5e67557b2ee88f855936b1e8aa1fc2e488536bb3 Mon Sep 17 00:00:00 2001 From: yx-keith Date: Sun, 23 Mar 2025 22:12:31 +0800 Subject: [PATCH 03/11] optimize import order --- .../main/java/org/apache/doris/statistics/AnalysisManager.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 ce05911f04a807..ce2572eff95aa3 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 @@ -61,8 +61,8 @@ 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.KillAnalyzeJobCommand; 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.TableNameInfo; import org.apache.doris.persist.AnalyzeDeletionLog; import org.apache.doris.persist.TableStatsDeletionLog; From f96ce9a500099711bb0a27935273b623b244d6b1 Mon Sep 17 00:00:00 2001 From: yx-keith Date: Sun, 23 Mar 2025 23:32:13 +0800 Subject: [PATCH 04/11] optimize test for Drop/KillAnalyzeJobCommand --- .../commands/DropAnalyzeJobCommandTest.java | 16 ---------------- .../commands/KillAnalyzeJobCommandTest.java | 16 ---------------- 2 files changed, 32 deletions(-) diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java index 430d4a1cb793e2..f1611ed827b4ef 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java @@ -17,11 +17,8 @@ package org.apache.doris.nereids.trees.plans.commands; -import org.apache.doris.backup.CatalogMocker; -import org.apache.doris.catalog.Database; import org.apache.doris.catalog.Env; import org.apache.doris.common.AnalysisException; -import org.apache.doris.datasource.InternalCatalog; import org.apache.doris.mysql.privilege.AccessControllerManager; import org.apache.doris.mysql.privilege.PrivPredicate; import org.apache.doris.qe.ConnectContext; @@ -32,33 +29,20 @@ import org.junit.jupiter.api.Test; public class DropAnalyzeJobCommandTest { - private static final String internalCtl = InternalCatalog.INTERNAL_CATALOG_NAME; @Mocked private Env env; @Mocked - private InternalCatalog catalog; - @Mocked private AccessControllerManager accessControllerManager; @Mocked private ConnectContext connectContext; - private Database db; private void runBefore() throws Exception { - db = CatalogMocker.mockDb(); new Expectations() { { Env.getCurrentEnv(); minTimes = 0; result = env; - env.getCatalogMgr().getCatalog(anyString); - minTimes = 0; - result = catalog; - - catalog.getDb(anyString); - minTimes = 0; - result = db; - env.getAccessManager(); minTimes = 0; result = accessControllerManager; diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java index 0216d52483cafe..94fde076c131a9 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java @@ -17,11 +17,8 @@ package org.apache.doris.nereids.trees.plans.commands; -import org.apache.doris.backup.CatalogMocker; -import org.apache.doris.catalog.Database; import org.apache.doris.catalog.Env; import org.apache.doris.common.AnalysisException; -import org.apache.doris.datasource.InternalCatalog; import org.apache.doris.mysql.privilege.AccessControllerManager; import org.apache.doris.mysql.privilege.PrivPredicate; import org.apache.doris.qe.ConnectContext; @@ -32,33 +29,20 @@ import org.junit.jupiter.api.Test; public class KillAnalyzeJobCommandTest { - private static final String internalCtl = InternalCatalog.INTERNAL_CATALOG_NAME; @Mocked private Env env; @Mocked - private InternalCatalog catalog; - @Mocked private AccessControllerManager accessControllerManager; @Mocked private ConnectContext connectContext; - private Database db; private void runBefore() throws Exception { - db = CatalogMocker.mockDb(); new Expectations() { { Env.getCurrentEnv(); minTimes = 0; result = env; - env.getCatalogMgr().getCatalog(anyString); - minTimes = 0; - result = catalog; - - catalog.getDb(anyString); - minTimes = 0; - result = db; - env.getAccessManager(); minTimes = 0; result = accessControllerManager; From 057adb1a6a496c105eecce17d478e2686fd70402 Mon Sep 17 00:00:00 2001 From: yx-keith Date: Mon, 24 Mar 2025 23:01:30 +0800 Subject: [PATCH 05/11] optimize jpbId in dropAnalyzeJobCommand --- .../doris/nereids/parser/LogicalPlanBuilder.java | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 e0d741f6cfb606..07edf99d3d926c 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 @@ -6312,14 +6312,16 @@ public LogicalPlan visitAlterColumnStats(DorisParser.AlterColumnStatsContext ctx properties); } - public LogicalPlan visitKillAnalyzeJob(DorisParser.KillAnalyzeJobContext ctx) { - long jobId = Long.parseLong(ctx.jobId.getText()); - return new KillAnalyzeJobCommand(jobId); - } - + @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); + } } From 256a2ab043e497513d0ae2a7f27c9b50f92629d3 Mon Sep 17 00:00:00 2001 From: yx-keith Date: Mon, 24 Mar 2025 23:33:22 +0800 Subject: [PATCH 06/11] add regression test --- .../statistics/test_drop_analyze_job.groovy | 53 +++++++++++++++++++ 1 file changed, 53 insertions(+) create mode 100644 regression-test/suites/statistics/test_drop_analyze_job.groovy 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 00000000000000..725ddfd4c4f9d7 --- /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()) + + def result = sql """show analyze drop_analyze_job_test""" + jobId0 = result[0][0] + + sql """drop analyze job $jobId0""" + + def result = sql """show analyze drop_analyze_job_test""" + assertEquals(0, result.size()) + + sql """drop database if exists test_drop_analyze_jobs""" +} + From bd836d143759ff672a0531d25e7a925c538100e7 Mon Sep 17 00:00:00 2001 From: yx-keith Date: Tue, 25 Mar 2025 09:08:35 +0800 Subject: [PATCH 07/11] optimize antlr syntax --- .../src/main/antlr4/org/apache/doris/nereids/DorisParser.g4 | 2 +- 1 file changed, 1 insertion(+), 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 b4f467ea8e86dd..6aa1292bdd7805 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 @@ -753,7 +753,7 @@ supportedStatsStatement ; unsupportedStatsStatement - | SHOW COLUMN CACHED? STATS tableName=multipartIdentifier + : SHOW COLUMN CACHED? STATS tableName=multipartIdentifier columnList=identifierList? partitionSpec? #showColumnStats | SHOW ANALYZE TASK STATUS jobId=INTEGER_VALUE #showAnalyzeTask ; From c1b5b7f344fba04bb90133fc03eae4582de79d3c Mon Sep 17 00:00:00 2001 From: yx-keith Date: Tue, 25 Mar 2025 11:09:12 +0800 Subject: [PATCH 08/11] optimize regression test --- regression-test/suites/statistics/test_drop_analyze_job.groovy | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/regression-test/suites/statistics/test_drop_analyze_job.groovy b/regression-test/suites/statistics/test_drop_analyze_job.groovy index 725ddfd4c4f9d7..d3fd8916c28bb4 100644 --- a/regression-test/suites/statistics/test_drop_analyze_job.groovy +++ b/regression-test/suites/statistics/test_drop_analyze_job.groovy @@ -43,7 +43,7 @@ suite("test_drop_analyze_job") { def result = sql """show analyze drop_analyze_job_test""" jobId0 = result[0][0] - sql """drop analyze job $jobId0""" + sql """drop analyze job ${jobId0}""" def result = sql """show analyze drop_analyze_job_test""" assertEquals(0, result.size()) From 3f4a049f172a18243e3d170e3b1d0e22c04c2e7f Mon Sep 17 00:00:00 2001 From: yx-keith Date: Tue, 25 Mar 2025 13:02:11 +0800 Subject: [PATCH 09/11] optimize regression test --- .../suites/statistics/test_drop_analyze_job.groovy | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/regression-test/suites/statistics/test_drop_analyze_job.groovy b/regression-test/suites/statistics/test_drop_analyze_job.groovy index d3fd8916c28bb4..f77509ac165436 100644 --- a/regression-test/suites/statistics/test_drop_analyze_job.groovy +++ b/regression-test/suites/statistics/test_drop_analyze_job.groovy @@ -40,12 +40,12 @@ suite("test_drop_analyze_job") { def result = sql """show analyze drop_analyze_job_test""" assertEquals(1, result.size()) - def result = sql """show analyze drop_analyze_job_test""" + result = sql """show analyze drop_analyze_job_test""" jobId0 = result[0][0] sql """drop analyze job ${jobId0}""" - def result = sql """show analyze drop_analyze_job_test""" + result = sql """show analyze drop_analyze_job_test""" assertEquals(0, result.size()) sql """drop database if exists test_drop_analyze_jobs""" From 606e7d519cf3d52631292eda78f57160a63f203a Mon Sep 17 00:00:00 2001 From: yx-keith Date: Wed, 26 Mar 2025 18:16:37 +0800 Subject: [PATCH 10/11] cancel validate function --- .../plans/commands/DropAnalyzeJobCommand.java | 8 -- .../plans/commands/KillAnalyzeJobCommand.java | 8 -- .../commands/DropAnalyzeJobCommandTest.java | 94 ------------------ .../commands/KillAnalyzeJobCommandTest.java | 95 ------------------- 4 files changed, 205 deletions(-) delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java delete mode 100644 fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java 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 index 0e8709507ffe21..7e5d2bf0218a01 100644 --- 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 @@ -45,17 +45,9 @@ public long getJobId() { @Override public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { - validate(); ctx.getEnv().getAnalysisManager().dropAnalyzeJob(this); } - public void validate() throws AnalysisException { - if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.DROP)) { - ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, "Permission denied", - ConnectContext.get().getQualifiedUser(), ConnectContext.get().getRemoteIP()); - } - } - @Override public R accept(PlanVisitor visitor, C context) { return visitor.visitDropAnalyzeJobCommand(this, context); 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 index 0f937850caa3e3..54fed2046a04bd 100644 --- 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 @@ -46,17 +46,9 @@ public long getJobId() { @Override public void doRun(ConnectContext ctx, StmtExecutor executor) throws Exception { - validate(); ctx.getEnv().getAnalysisManager().handleKillAnalyzeJob(this); } - public void validate() throws AnalysisException { - if (!Env.getCurrentEnv().getAccessManager().checkGlobalPriv(ConnectContext.get(), PrivPredicate.DROP)) { - ErrorReport.reportAnalysisException(ErrorCode.ERR_TABLEACCESS_DENIED_ERROR, "Permission denied", - ConnectContext.get().getQualifiedUser(), ConnectContext.get().getRemoteIP()); - } - } - @Override public R accept(PlanVisitor visitor, C context) { return visitor.visitKillAnalyzeJobCommand(this, context); diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java deleted file mode 100644 index f1611ed827b4ef..00000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/DropAnalyzeJobCommandTest.java +++ /dev/null @@ -1,94 +0,0 @@ -// 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.Env; -import org.apache.doris.common.AnalysisException; -import org.apache.doris.mysql.privilege.AccessControllerManager; -import org.apache.doris.mysql.privilege.PrivPredicate; -import org.apache.doris.qe.ConnectContext; - -import mockit.Expectations; -import mockit.Mocked; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class DropAnalyzeJobCommandTest { - @Mocked - private Env env; - @Mocked - private AccessControllerManager accessControllerManager; - @Mocked - private ConnectContext connectContext; - - private void runBefore() throws Exception { - new Expectations() { - { - Env.getCurrentEnv(); - minTimes = 0; - result = env; - - env.getAccessManager(); - minTimes = 0; - result = accessControllerManager; - - ConnectContext.get(); - minTimes = 0; - result = connectContext; - - connectContext.isSkipAuth(); - minTimes = 0; - result = true; - - accessControllerManager.checkGlobalPriv(connectContext, PrivPredicate.DROP); - minTimes = 0; - result = true; - } - }; - } - - @Test - public void testValidateNormal() throws Exception { - runBefore(); - DropAnalyzeJobCommand command = new DropAnalyzeJobCommand(10000); - Assertions.assertDoesNotThrow(() -> command.validate()); - } - - @Test - void testValidateNoPrivilege() { - new Expectations() { - { - Env.getCurrentEnv(); - minTimes = 0; - result = env; - - env.getAccessManager(); - minTimes = 0; - result = accessControllerManager; - - accessControllerManager.checkGlobalPriv(connectContext, PrivPredicate.DROP); - minTimes = 0; - result = false; - } - }; - - DropAnalyzeJobCommand command = new DropAnalyzeJobCommand(10000); - Assertions.assertThrows(AnalysisException.class, () -> command.validate(), - "Permission denied command denied to user 'null'@'null' for table 'null'"); - } -} diff --git a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java b/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java deleted file mode 100644 index 94fde076c131a9..00000000000000 --- a/fe/fe-core/src/test/java/org/apache/doris/nereids/trees/plans/commands/KillAnalyzeJobCommandTest.java +++ /dev/null @@ -1,95 +0,0 @@ -// 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.Env; -import org.apache.doris.common.AnalysisException; -import org.apache.doris.mysql.privilege.AccessControllerManager; -import org.apache.doris.mysql.privilege.PrivPredicate; -import org.apache.doris.qe.ConnectContext; - -import mockit.Expectations; -import mockit.Mocked; -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; - -public class KillAnalyzeJobCommandTest { - @Mocked - private Env env; - @Mocked - private AccessControllerManager accessControllerManager; - @Mocked - private ConnectContext connectContext; - - private void runBefore() throws Exception { - new Expectations() { - { - Env.getCurrentEnv(); - minTimes = 0; - result = env; - - env.getAccessManager(); - minTimes = 0; - result = accessControllerManager; - - ConnectContext.get(); - minTimes = 0; - result = connectContext; - - connectContext.isSkipAuth(); - minTimes = 0; - result = true; - - accessControllerManager.checkGlobalPriv(connectContext, PrivPredicate.DROP); - minTimes = 0; - result = true; - } - }; - } - - @Test - public void testValidateNormal() throws Exception { - runBefore(); - KillAnalyzeJobCommand command = new KillAnalyzeJobCommand(10000); - Assertions.assertDoesNotThrow(() -> command.validate()); - } - - @Test - void testValidateNoPrivilege() { - new Expectations() { - { - Env.getCurrentEnv(); - minTimes = 0; - result = env; - - env.getAccessManager(); - minTimes = 0; - result = accessControllerManager; - - accessControllerManager.checkGlobalPriv(connectContext, PrivPredicate.DROP); - minTimes = 0; - result = false; - } - }; - - KillAnalyzeJobCommand command = new KillAnalyzeJobCommand(10000); - Assertions.assertThrows(AnalysisException.class, () -> command.validate(), - "Permission denied command denied to user 'null'@'null' for table 'null'"); - } - -} From 8194d3d84002ad5408bcbc41edf277070de414fb Mon Sep 17 00:00:00 2001 From: yx-keith Date: Wed, 26 Mar 2025 20:51:40 +0800 Subject: [PATCH 11/11] optimize import --- .../nereids/trees/plans/commands/DropAnalyzeJobCommand.java | 5 ----- .../nereids/trees/plans/commands/KillAnalyzeJobCommand.java | 5 ----- 2 files changed, 10 deletions(-) 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 index 7e5d2bf0218a01..402e5c55750983 100644 --- 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 @@ -18,11 +18,6 @@ package org.apache.doris.nereids.trees.plans.commands; import org.apache.doris.analysis.StmtType; -import org.apache.doris.catalog.Env; -import org.apache.doris.common.AnalysisException; -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; 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 index 54fed2046a04bd..3c363cba9b2cda 100644 --- 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 @@ -18,11 +18,6 @@ package org.apache.doris.nereids.trees.plans.commands; import org.apache.doris.analysis.StmtType; -import org.apache.doris.catalog.Env; -import org.apache.doris.common.AnalysisException; -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;