[SPARK-23001][SQL] Fix NullPointerException when DESC a database with NULL description
## What changes were proposed in this pull request? When users' DB description is NULL, users might hit `NullPointerException`. This PR is to fix the issue. ## How was this patch tested? Added test cases Author: gatorsmile <gatorsmile@gmail.com> Closes #20215 from gatorsmile/SPARK-23001.
This commit is contained in:
parent
a6647ffbf7
commit
87c98de8b2
|
@ -330,7 +330,7 @@ private[hive] class HiveClientImpl(
|
||||||
Option(client.getDatabase(dbName)).map { d =>
|
Option(client.getDatabase(dbName)).map { d =>
|
||||||
CatalogDatabase(
|
CatalogDatabase(
|
||||||
name = d.getName,
|
name = d.getName,
|
||||||
description = d.getDescription,
|
description = Option(d.getDescription).getOrElse(""),
|
||||||
locationUri = CatalogUtils.stringToURI(d.getLocationUri),
|
locationUri = CatalogUtils.stringToURI(d.getLocationUri),
|
||||||
properties = Option(d.getParameters).map(_.asScala.toMap).orNull)
|
properties = Option(d.getParameters).map(_.asScala.toMap).orNull)
|
||||||
}.getOrElse(throw new NoSuchDatabaseException(dbName))
|
}.getOrElse(throw new NoSuchDatabaseException(dbName))
|
||||||
|
|
|
@ -107,4 +107,10 @@ class HiveExternalCatalogSuite extends ExternalCatalogSuite {
|
||||||
.filter(_.contains("Num Buckets")).head
|
.filter(_.contains("Num Buckets")).head
|
||||||
assert(bucketString.contains("10"))
|
assert(bucketString.contains("10"))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test("SPARK-23001: NullPointerException when running desc database") {
|
||||||
|
val catalog = newBasicCatalog()
|
||||||
|
catalog.createDatabase(newDb("dbWithNullDesc").copy(description = null), ignoreIfExists = false)
|
||||||
|
assert(catalog.getDatabase("dbWithNullDesc").description == "")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -163,6 +163,15 @@ class VersionsSuite extends SparkFunSuite with Logging {
|
||||||
client.createDatabase(tempDB, ignoreIfExists = true)
|
client.createDatabase(tempDB, ignoreIfExists = true)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
test(s"$version: createDatabase with null description") {
|
||||||
|
withTempDir { tmpDir =>
|
||||||
|
val dbWithNullDesc =
|
||||||
|
CatalogDatabase("dbWithNullDesc", description = null, tmpDir.toURI, Map())
|
||||||
|
client.createDatabase(dbWithNullDesc, ignoreIfExists = true)
|
||||||
|
assert(client.getDatabase("dbWithNullDesc").description == "")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
test(s"$version: setCurrentDatabase") {
|
test(s"$version: setCurrentDatabase") {
|
||||||
client.setCurrentDatabase("default")
|
client.setCurrentDatabase("default")
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue