Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -565,6 +565,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.DropCachedStatsCommand;
import org.apache.doris.nereids.trees.plans.commands.DropCatalogCommand;
import org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand;
Expand All @@ -591,6 +592,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;
Expand Down Expand Up @@ -6324,5 +6326,17 @@ public LogicalPlan visitAlterColumnStats(DorisParser.AlterColumnStatsContext ctx
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);
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -324,5 +324,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
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.DropCachedStatsCommand;
import org.apache.doris.nereids.trees.plans.commands.DropCatalogCommand;
import org.apache.doris.nereids.trees.plans.commands.DropCatalogRecycleBinCommand;
Expand All @@ -88,6 +89,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;
Expand Down Expand Up @@ -899,4 +901,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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,9 @@
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;
Expand Down Expand Up @@ -1166,6 +1168,23 @@ public void updateRemotePartitionStats(long catalogId, long dbId, long tableId,
}
}

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) {
Expand Down Expand Up @@ -1335,6 +1354,19 @@ public void removeAll(List<AnalysisInfo> 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) {
Expand Down
53 changes: 53 additions & 0 deletions regression-test/suites/statistics/test_drop_analyze_job.groovy
Original file line number Diff line number Diff line change
@@ -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"""
}

Loading