From f33098d853c00f0547e7acc7cec28ddd7c96159f Mon Sep 17 00:00:00 2001 From: Vallish Date: Thu, 7 Nov 2024 16:46:40 +0000 Subject: [PATCH] review fix --- .../trees/plans/commands/RecoverCommand.java | 45 +++++++++++++++++++ .../commands/RecoverDatabaseCommand.java | 18 +++----- .../ddl/recover}/test_recover_db.out | 0 .../ddl/recover}/test_recover_db.groovy | 4 +- 4 files changed, 52 insertions(+), 15 deletions(-) create mode 100644 fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RecoverCommand.java rename regression-test/data/{ddl_p0 => nereids_p0/ddl/recover}/test_recover_db.out (100%) rename regression-test/suites/{ddl_p0 => nereids_p0/ddl/recover}/test_recover_db.groovy (96%) diff --git a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RecoverCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RecoverCommand.java new file mode 100644 index 00000000000000..a07178102af270 --- /dev/null +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RecoverCommand.java @@ -0,0 +1,45 @@ +// 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 recover commands + */ +public abstract class RecoverCommand extends Command implements ForwardWithSync { + public RecoverCommand(PlanType type) { + super(type); + } + + @Override + public StmtType stmtType() { + return StmtType.RECOVER; + } + + @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/commands/RecoverDatabaseCommand.java b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RecoverDatabaseCommand.java index bb2a4e43e62fa4..c995544abe2661 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RecoverDatabaseCommand.java +++ b/fe/fe-core/src/main/java/org/apache/doris/nereids/trees/plans/commands/RecoverDatabaseCommand.java @@ -17,7 +17,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.ErrorCode; import org.apache.doris.common.ErrorReport; @@ -36,12 +35,12 @@ /** * recover database command */ -public class RecoverDatabaseCommand extends Command implements ForwardWithSync { +public class RecoverDatabaseCommand extends RecoverCommand { public static final Logger LOG = LogManager.getLogger(RecoverDatabaseCommand.class); private final String dbName; - private final long dbId = -1; - private final String newDbName = ""; + private final long dbId; + private final String newDbName; /** * constructor @@ -51,9 +50,7 @@ public RecoverDatabaseCommand(String dbName, long dbId, String newDbName) { super(PlanType.RECOVER_DATABASE_COMMAND); this.dbName = dbName; this.dbId = dbId; - if (newDbName != null) { - this.newDbName = newDbName; - } + this.newDbName = newDbName; } public String getDbName() { @@ -69,7 +66,7 @@ public String getNewDbName() { } @Override - public void run(ConnectContext ctx, StmtExecutor executor) throws UserException { + public void doRun(ConnectContext ctx, StmtExecutor executor) throws UserException { if (Strings.isNullOrEmpty(dbName)) { ErrorReport.reportAnalysisException(ErrorCode.ERR_WRONG_DB_NAME, dbName); } @@ -88,9 +85,4 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws UserException public R accept(PlanVisitor visitor, C context) { return visitor.visitRecoverDatabaseCommand(this, context); } - - @Override - public StmtType stmtType() { - return StmtType.RECOVER; - } } diff --git a/regression-test/data/ddl_p0/test_recover_db.out b/regression-test/data/nereids_p0/ddl/recover/test_recover_db.out similarity index 100% rename from regression-test/data/ddl_p0/test_recover_db.out rename to regression-test/data/nereids_p0/ddl/recover/test_recover_db.out diff --git a/regression-test/suites/ddl_p0/test_recover_db.groovy b/regression-test/suites/nereids_p0/ddl/recover/test_recover_db.groovy similarity index 96% rename from regression-test/suites/ddl_p0/test_recover_db.groovy rename to regression-test/suites/nereids_p0/ddl/recover/test_recover_db.groovy index c5e83235b0ce78..b6af5af2aad9f3 100644 --- a/regression-test/suites/ddl_p0/test_recover_db.groovy +++ b/regression-test/suites/nereids_p0/ddl/recover/test_recover_db.groovy @@ -68,13 +68,13 @@ suite("test_recover_db") { qt_select "show tables"; sql " drop database $db" - sql " recover database $db" + checkNereidsExecute("recover database $db;") sql " use $db" qt_select1 "show tables"; def newdb="new_recover_db" sql " drop database IF EXISTS $newdb FORCE" sql " drop database $db" - sql " recover database $db as $newdb" + checkNereidsExecute("recover database $db as $newdb;") sql " use $newdb" qt_select2 "show tables";