Skip to content

Commit

Permalink
review fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Vallishp committed Nov 14, 2024
1 parent 31be9bf commit f33098d
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 15 deletions.
Original file line number Diff line number Diff line change
@@ -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;

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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() {
Expand All @@ -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);
}
Expand All @@ -88,9 +85,4 @@ public void run(ConnectContext ctx, StmtExecutor executor) throws UserException
public <R, C> R accept(PlanVisitor<R, C> visitor, C context) {
return visitor.visitRecoverDatabaseCommand(this, context);
}

@Override
public StmtType stmtType() {
return StmtType.RECOVER;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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";
Expand Down

0 comments on commit f33098d

Please sign in to comment.