Skip to content

Commit

Permalink
[fix](drop sql) add force in the tosql for drop table and drop databa…
Browse files Browse the repository at this point in the history
…se (#43227)



1. What problem was fixed (it's best to include specific error reporting
information). How it was fixed.
2. Which behaviors were modified. What was the previous behavior, what
is it now, why was it modified, and what possible impacts might there
be.
3. What features were added. Why this function was added.
4. Which codes were refactored and why this part of the code was
refactored.
5. Which functions were optimized and what is the difference before and
after the optimization.
  • Loading branch information
Vallishp authored Nov 22, 2024
1 parent 82f33c2 commit db02ca1
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 3 deletions.
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

0 comments on commit db02ca1

Please sign in to comment.