cloud-fan commented on a change in pull request #35113:
URL: https://github.com/apache/spark/pull/35113#discussion_r780453457



##########
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]

Reply via email to