Skip to content
Closed
Show file tree
Hide file tree
Changes from 1 commit
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 @@ -220,15 +220,14 @@ private[spark] class HiveExternalCatalog(conf: SparkConf, hadoopConf: Configurat
override def dropDatabase(
db: String,
ignoreIfNotExists: Boolean,
cascade: Boolean): Unit = withClient {
try {
client.dropDatabase(db, ignoreIfNotExists, cascade)
} catch {
case NonFatal(exception) =>
if (exception.getClass.getName.equals("org.apache.hadoop.hive.ql.metadata.HiveException")
&& exception.getMessage.contains(s"Database $db is not empty.")) {
throw QueryCompilationErrors.cannotDropNonemptyDatabaseError(db)
} else throw exception
cascade: Boolean): Unit = withClientWrappingException {
client.dropDatabase(db, ignoreIfNotExists, cascade)
} { exception =>
if (exception.getClass.getName.equals("org.apache.hadoop.hive.ql.metadata.HiveException")
&& exception.getMessage.contains(s"Database $db is not empty")) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cloud-fan Note that I removed . when checking the message.
For Hive 0.12, the exception message is InvalidOperationException(message:Database temporary is not empty), whereas for Hive >0.12, the message is [InvalidOperationException(message:Database temporary is not empty. One or more tables exist.)]. So the wrapping wasn't working for Hive 0.12.

throw QueryCompilationErrors.cannotDropNonemptyDatabaseError(db)
} else {
None
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -275,6 +275,16 @@ class VersionsSuite extends SparkFunSuite with Logging {

test(s"$version: dropDatabase") {
assert(client.databaseExists("temporary"))
client.createTable(table("temporary", tableName = "tbl"), ignoreIfExists = false)
try {
client.dropDatabase("temporary", ignoreIfNotExists = false, cascade = false)
assert(false, "dropDatabase should throw HiveException")
} catch {
case ex: Throwable =>
assert(ex.getClass.getName.equals("org.apache.hadoop.hive.ql.metadata.HiveException"))
assert(ex.getMessage.contains("Database temporary is not empty"))
}

client.dropDatabase("temporary", ignoreIfNotExists = false, cascade = true)
assert(client.databaseExists("temporary") == false)
}
Expand Down