You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@spark.apache.org by an...@apache.org on 2016/11/23 17:54:21 UTC

spark git commit: [SPARK-18050][SQL] do not create default database if it already exists

Repository: spark
Updated Branches:
  refs/heads/master 70ad07a9d -> f129ebcd3


[SPARK-18050][SQL] do not create default database if it already exists

## What changes were proposed in this pull request?

When we try to create the default database, we ask hive to do nothing if it already exists. However, Hive will log an error message instead of doing nothing, and the error message is quite annoying and confusing.

In this PR, we only create default database if it doesn't exist.

## How was this patch tested?

N/A

Author: Wenchen Fan <we...@databricks.com>

Closes #15993 from cloud-fan/default-db.


Project: http://git-wip-us.apache.org/repos/asf/spark/repo
Commit: http://git-wip-us.apache.org/repos/asf/spark/commit/f129ebcd
Tree: http://git-wip-us.apache.org/repos/asf/spark/tree/f129ebcd
Diff: http://git-wip-us.apache.org/repos/asf/spark/diff/f129ebcd

Branch: refs/heads/master
Commit: f129ebcd302168b628f47705f4a7d6b7e7b057b0
Parents: 70ad07a
Author: Wenchen Fan <we...@databricks.com>
Authored: Wed Nov 23 12:54:18 2016 -0500
Committer: Andrew Or <an...@gmail.com>
Committed: Wed Nov 23 12:54:18 2016 -0500

----------------------------------------------------------------------
 .../scala/org/apache/spark/sql/internal/SharedState.scala    | 8 ++++++--
 1 file changed, 6 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/spark/blob/f129ebcd/sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala
----------------------------------------------------------------------
diff --git a/sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala b/sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala
index 6232c18..8de95fe 100644
--- a/sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala
+++ b/sql/core/src/main/scala/org/apache/spark/sql/internal/SharedState.scala
@@ -92,8 +92,12 @@ private[sql] class SharedState(val sparkContext: SparkContext) extends Logging {
   {
     val defaultDbDefinition = CatalogDatabase(
       SessionCatalog.DEFAULT_DATABASE, "default database", warehousePath, Map())
-    // Initialize default database if it doesn't already exist
-    externalCatalog.createDatabase(defaultDbDefinition, ignoreIfExists = true)
+    // Initialize default database if it doesn't exist
+    if (!externalCatalog.databaseExists(SessionCatalog.DEFAULT_DATABASE)) {
+      // There may be another Spark application creating default database at the same time, here we
+      // set `ignoreIfExists = true` to avoid `DatabaseAlreadyExists` exception.
+      externalCatalog.createDatabase(defaultDbDefinition, ignoreIfExists = true)
+    }
   }
 
   /**


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@spark.apache.org
For additional commands, e-mail: commits-help@spark.apache.org