Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[fix](drop sql) add force in the tosql for drop table and drop database #43227

Merged
merged 1 commit into from
Nov 22, 2024
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 @@ -88,6 +88,9 @@ public void analyze(Analyzer analyzer) throws UserException {
public String toSql() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("DROP DATABASE ").append("`").append(dbName).append("`");
if (forceDrop) {
stringBuilder.append(" FORCE");
}
return stringBuilder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,9 @@ public void analyze(Analyzer analyzer) throws UserException {
public String toSql() {
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("DROP TABLE ").append(tableName.toSql());
if (forceDrop) {
stringBuilder.append(" FORCE");
}
return stringBuilder.toString();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,14 +45,24 @@ public void setUp() {

@Test
public void testNormal() throws UserException, AnalysisException {
DropDbStmt stmt = new DropDbStmt(false, new DbName("test", "test"), true);
DropDbStmt stmt = new DropDbStmt(false, new DbName("test", "test"), false);

stmt.analyze(analyzer);
Assert.assertEquals("test", stmt.getCtlName());
Assert.assertEquals("test", stmt.getDbName());
Assert.assertEquals("DROP DATABASE `test`", stmt.toString());
}

@Test
public void testForce() throws UserException, AnalysisException {
DropDbStmt stmt = new DropDbStmt(false, new DbName("test", "test"), true);

stmt.analyze(analyzer);
Assert.assertEquals("test", stmt.getCtlName());
Assert.assertEquals("test", stmt.getDbName());
Assert.assertEquals("DROP DATABASE `test` FORCE", stmt.toString());
}

@Test(expected = AnalysisException.class)
public void testFailed() throws UserException, AnalysisException {
DropDbStmt stmt = new DropDbStmt(false, new DbName("", ""), true);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,12 +72,13 @@ public void testNormal() throws UserException, AnalysisException {
stmt.analyze(analyzer);
Assert.assertEquals("db1", stmt.getDbName());
Assert.assertEquals("table1", stmt.getTableName());
Assert.assertEquals("DROP TABLE `db1`.`table1`", stmt.toString());
// one with force.
Assert.assertEquals("DROP TABLE `db1`.`table1` FORCE", stmt.toString());
}

@Test
public void testDefaultNormal() throws UserException, AnalysisException {
DropTableStmt stmt = new DropTableStmt(false, noDbTbl, true);
DropTableStmt stmt = new DropTableStmt(false, noDbTbl, false);
stmt.analyze(analyzer);
Assert.assertEquals("testDb", stmt.getDbName());
Assert.assertEquals("table1", stmt.getTableName());
Expand Down
Loading