Skip to content

Commit 8aa1c2d

Browse files
committed
Keep the current behavior and add new error message for dropping current db.
1 parent ac5f3ea commit 8aa1c2d

File tree

3 files changed

+12
-12
lines changed

3 files changed

+12
-12
lines changed

sql/catalyst/src/main/scala/org/apache/spark/sql/catalyst/catalog/SessionCatalog.scala

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,8 +148,10 @@ class SessionCatalog(
148148

149149
def dropDatabase(db: String, ignoreIfNotExists: Boolean, cascade: Boolean): Unit = {
150150
val dbName = formatDatabaseName(db)
151-
if (dbName == DEFAULT_DATABASE || dbName == getCurrentDatabase) {
152-
throw new AnalysisException(s"Can not drop `${DEFAULT_DATABASE}` or current database")
151+
if (dbName == DEFAULT_DATABASE) {
152+
throw new AnalysisException(s"Can not drop default database")
153+
} else if (dbName == getCurrentDatabase) {
154+
throw new AnalysisException(s"Can not drop current database `${dbName}`")
153155
}
154156
externalCatalog.dropDatabase(dbName, ignoreIfNotExists, cascade)
155157
}

sql/core/src/test/scala/org/apache/spark/sql/execution/command/DDLSuite.scala

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1270,28 +1270,30 @@ class DDLSuite extends QueryTest with SharedSQLContext with BeforeAndAfterEach {
12701270
"WITH SERDEPROPERTIES ('spark.sql.sources.me'='anything')")
12711271
}
12721272

1273-
test("drop default or current database") {
1273+
test("drop current database") {
12741274
sql("CREATE DATABASE temp")
12751275
sql("USE temp")
12761276
val m = intercept[AnalysisException] {
12771277
sql("DROP DATABASE temp")
12781278
}.getMessage
1279-
assert(m.contains("Can not drop `default` or current database"))
1279+
assert(m.contains("Can not drop current database `temp`"))
1280+
}
12801281

1282+
test("drop default database") {
12811283
Seq("true", "false").foreach { caseSensitive =>
12821284
withSQLConf(SQLConf.CASE_SENSITIVE.key -> caseSensitive) {
12831285
var message = intercept[AnalysisException] {
12841286
sql("DROP DATABASE default")
12851287
}.getMessage
1286-
assert(message.contains("Can not drop `default` or current database"))
1288+
assert(message.contains("Can not drop default database"))
12871289

12881290
message = intercept[AnalysisException] {
12891291
sql("DROP DATABASE DeFault")
12901292
}.getMessage
12911293
if (caseSensitive == "true") {
12921294
assert(message.contains("Database 'DeFault' not found"))
12931295
} else {
1294-
assert(message.contains("Can not drop `default` or current database"))
1296+
assert(message.contains("Can not drop default database"))
12951297
}
12961298
}
12971299
}

sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/HiveDDLSuite.scala

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -567,18 +567,14 @@ class HiveDDLSuite
567567
var message = intercept[AnalysisException] {
568568
sql("DROP DATABASE default")
569569
}.getMessage
570-
assert(message.contains("Can not drop `default` or current database"))
570+
assert(message.contains("Can not drop default database"))
571571

572572
// SQLConf.CASE_SENSITIVE does not affect the result
573573
// because the Hive metastore is not case sensitive.
574574
message = intercept[AnalysisException] {
575575
sql("DROP DATABASE DeFault")
576576
}.getMessage
577-
if (caseSensitive == "true") {
578-
assert(message.contains("Can not drop default database"))
579-
} else {
580-
assert(message.contains("Can not drop `default` or current database"))
581-
}
577+
assert(message.contains("Can not drop default database"))
582578
}
583579
}
584580
}

0 commit comments

Comments
 (0)