diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropDbStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropDbStmt.java index 2715bd1f6da2f9..47fdfdce4e23c8 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropDbStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropDbStmt.java @@ -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(); } diff --git a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropTableStmt.java b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropTableStmt.java index 5e06fce75ee074..d6a19e81f8e3f4 100644 --- a/fe/fe-core/src/main/java/org/apache/doris/analysis/DropTableStmt.java +++ b/fe/fe-core/src/main/java/org/apache/doris/analysis/DropTableStmt.java @@ -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(); } diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/DropDbStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/DropDbStmtTest.java index 67b44adc565534..f14f5113d8feea 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/DropDbStmtTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/DropDbStmtTest.java @@ -45,7 +45,7 @@ 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()); @@ -53,6 +53,16 @@ public void testNormal() throws UserException, AnalysisException { 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); diff --git a/fe/fe-core/src/test/java/org/apache/doris/analysis/DropTableStmtTest.java b/fe/fe-core/src/test/java/org/apache/doris/analysis/DropTableStmtTest.java index da6d5b8d4c44d0..437e54f58f20e6 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/analysis/DropTableStmtTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/analysis/DropTableStmtTest.java @@ -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());