This is an automated email from the ASF dual-hosted git repository. morningman pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/incubator-doris.git
The following commit(s) were added to refs/heads/master by this push: new a52104f [Bug] Fix bug that DROP SCHEMA will forcibly database (#6729) a52104f is described below commit a52104fe40e82fd4f7e7690df1b80890e99379d5 Author: Mingyu Chen <morningman....@gmail.com> AuthorDate: Fri Sep 24 10:35:40 2021 +0800 [Bug] Fix bug that DROP SCHEMA will forcibly database (#6729) --- fe/fe-core/src/main/cup/sql_parser.cup | 4 +-- .../java/org/apache/doris/catalog/DropDbTest.java | 32 +++++++++++++++++++++- 2 files changed, 33 insertions(+), 3 deletions(-) diff --git a/fe/fe-core/src/main/cup/sql_parser.cup b/fe/fe-core/src/main/cup/sql_parser.cup index c8d28a4..6d4f703 100644 --- a/fe/fe-core/src/main/cup/sql_parser.cup +++ b/fe/fe-core/src/main/cup/sql_parser.cup @@ -1950,9 +1950,9 @@ drop_stmt ::= {: RESULT = new DropDbStmt(ifExists, db, force); :} - | KW_DROP KW_SCHEMA opt_force:force opt_if_exists:ifExists ident:db + | KW_DROP KW_SCHEMA opt_if_exists:ifExists ident:db opt_force:force {: - RESULT = new DropDbStmt(ifExists, db, !force); + RESULT = new DropDbStmt(ifExists, db, force); :} /* cluster */ | KW_DROP KW_CLUSTER opt_if_exists:ifExists ident:cluster diff --git a/fe/fe-core/src/test/java/org/apache/doris/catalog/DropDbTest.java b/fe/fe-core/src/test/java/org/apache/doris/catalog/DropDbTest.java index 0a97a1d..ca2f1cb 100644 --- a/fe/fe-core/src/test/java/org/apache/doris/catalog/DropDbTest.java +++ b/fe/fe-core/src/test/java/org/apache/doris/catalog/DropDbTest.java @@ -49,12 +49,14 @@ public class DropDbTest { // create database String createDbStmtStr1 = "create database test1;"; String createDbStmtStr2 = "create database test2;"; + String createDbStmtStr3 = "create database test3;"; String createTablleStr1 = "create table test1.tbl1(k1 int, k2 bigint) duplicate key(k1) " + "distributed by hash(k2) buckets 1" + " properties('replication_num' = '1');"; String createTablleStr2 = "create table test2.tbl1" + "(k1 int, k2 bigint)" + " duplicate key(k1) " + "distributed by hash(k2) buckets 1 " + "properties('replication_num' = '1');"; createDb(createDbStmtStr1); createDb(createDbStmtStr2); + createDb(createDbStmtStr3); createTable(createTablleStr1); createTable(createTablleStr2); } @@ -89,8 +91,8 @@ public class DropDbTest { String dropDbSql = "drop database test1"; dropDb(dropDbSql); db = Catalog.getCurrentCatalog().getDbNullable("default_cluster:test1"); - List<Replica> replicaList = Catalog.getCurrentCatalog().getTabletInvertedIndex().getReplicasByTabletId(tabletId); Assert.assertNull(db); + List<Replica> replicaList = Catalog.getCurrentCatalog().getTabletInvertedIndex().getReplicasByTabletId(tabletId); Assert.assertEquals(1, replicaList.size()); String recoverDbSql = "recover database test1"; RecoverDbStmt recoverDbStmt = (RecoverDbStmt) UtFrameUtils.parseAndAnalyzeStmt(recoverDbSql, connectContext); @@ -101,6 +103,19 @@ public class DropDbTest { table = (OlapTable) db.getTableOrMetaException("tbl1"); Assert.assertNotNull(table); Assert.assertEquals("tbl1", table.getName()); + + dropDbSql = "drop schema test1"; + dropDb(dropDbSql); + db = Catalog.getCurrentCatalog().getDbNullable("default_cluster:test1"); + Assert.assertNull(db); + Catalog.getCurrentCatalog().recoverDatabase(recoverDbStmt); + db = Catalog.getCurrentCatalog().getDbNullable("default_cluster:test1"); + Assert.assertNotNull(db); + + dropDbSql = "drop schema if exists test1"; + dropDb(dropDbSql); + db = Catalog.getCurrentCatalog().getDbNullable("default_cluster:test1"); + Assert.assertNull(db); } @Test @@ -120,5 +135,20 @@ public class DropDbTest { ExceptionChecker.expectThrowsWithMsg(DdlException.class, "Unknown database 'default_cluster:test2'", () -> Catalog.getCurrentCatalog().recoverDatabase(recoverDbStmt)); + + dropDbSql = "drop schema test3 force"; + db = Catalog.getCurrentCatalog().getDbOrMetaException("default_cluster:test3"); + Assert.assertNotNull(db); + dropDb(dropDbSql); + db = Catalog.getCurrentCatalog().getDbNullable("default_cluster:test3"); + Assert.assertNull(db); + recoverDbSql = "recover database test3"; + RecoverDbStmt recoverDbStmt2 = (RecoverDbStmt) UtFrameUtils.parseAndAnalyzeStmt(recoverDbSql, connectContext); + ExceptionChecker.expectThrowsWithMsg(DdlException.class, + "Unknown database 'default_cluster:test3'", + () -> Catalog.getCurrentCatalog().recoverDatabase(recoverDbStmt2)); + + dropDbSql = "drop schema if exists test3 force"; + dropDb(dropDbSql); } } --------------------------------------------------------------------- To unsubscribe, e-mail: commits-unsubscr...@doris.apache.org For additional commands, e-mail: commits-h...@doris.apache.org