Skip to content

Commit

Permalink
HiveOps createDatabase always fails on existence test
Browse files Browse the repository at this point in the history
  • Loading branch information
hannesmiller committed Mar 30, 2018
1 parent 2b1a9e9 commit 18ebcbb
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion eel-hive/src/main/scala/io/eels/component/hive/HiveOps.scala
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package io.eels.component.hive

import java.rmi.NoSuchObjectException

import com.sksamuel.exts.Logging
import io.eels.Constants
import io.eels.component.hive.dialect.ParquetHiveDialect
Expand Down Expand Up @@ -267,7 +269,7 @@ class HiveOps(val client: IMetaStoreClient) extends Logging {
}

def createDatabase(name: String, description: String = null, overwrite: Boolean = false): Unit = client.synchronized {
val exists = client.getDatabase(name) != null
val exists = databaseExists(name)
if (exists && overwrite) {
logger.info(s"Database exists, overwrite=true; dropping database $name")
client.dropDatabase(name)
Expand All @@ -278,4 +280,12 @@ class HiveOps(val client: IMetaStoreClient) extends Logging {
client.createDatabase(database)
}
}

def databaseExists(name: String): Boolean = {
try {
client.getDatabase(name) != null
} catch {
case _: NoSuchObjectException => false
}
}
}

0 comments on commit 18ebcbb

Please sign in to comment.