cloud-fan commented on a change in pull request #35113:
URL: https://github.com/apache/spark/pull/35113#discussion_r780084161
##########
File path:
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala
##########
@@ -189,8 +189,15 @@ private[spark] class HiveExternalCatalog(conf: SparkConf,
hadoopConf: Configurat
override def createDatabase(
dbDefinition: CatalogDatabase,
- ignoreIfExists: Boolean): Unit = withClient {
- client.createDatabase(dbDefinition, ignoreIfExists)
+ ignoreIfExists: Boolean): Unit = {
+ try {
+ withClient {
+ client.createDatabase(dbDefinition, ignoreIfExists)
+ }
+ } catch {
+ case e: AnalysisException if e.message.contains("already exists") =>
+ throw new DatabaseAlreadyExistsException(dbDefinition.name)
Review comment:
shall we put this logic in `withClient`?
##########
File path:
sql/hive/src/test/scala/org/apache/spark/sql/hive/execution/command/CreateNamespaceSuite.scala
##########
@@ -25,5 +25,4 @@ import org.apache.spark.sql.execution.command.v1
*/
class CreateNamespaceSuite extends v1.CreateNamespaceSuiteBase with
CommandSuiteBase {
override def commandVersion: String =
super[CreateNamespaceSuiteBase].commandVersion
- override def alreadyExistErrorMessage: String = s"$notFoundMsgPrefix
$namespace already exists"
Review comment:
shall we remove it from the base class as well?
##########
File path:
sql/hive/src/main/scala/org/apache/spark/sql/hive/HiveExternalCatalog.scala
##########
@@ -189,8 +189,15 @@ private[spark] class HiveExternalCatalog(conf: SparkConf,
hadoopConf: Configurat
override def createDatabase(
dbDefinition: CatalogDatabase,
- ignoreIfExists: Boolean): Unit = withClient {
- client.createDatabase(dbDefinition, ignoreIfExists)
+ ignoreIfExists: Boolean): Unit = {
+ try {
+ withClient {
+ client.createDatabase(dbDefinition, ignoreIfExists)
+ }
+ } catch {
+ case e: AnalysisException if e.message.contains("already exists") =>
+ throw new DatabaseAlreadyExistsException(dbDefinition.name)
Review comment:
You made a good point. But it's still a bit hacky that we wrap the
exception multiple times. How about
```
def withClient(convertException: Throwable => AnalysisException, body: => T)
...
def withClient(body: => T) = withClient(e => throw new AnalysisException...,
body)
```
Then we can call the new overload of `withClient` in `createDatabase` and
translate the hive exception directly. We can probably apply it in more places
like `createTable` when we need to unify the error message further.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]