title: Failing to Drop Database in Hive
body: <p>I'm trying to initialize database in hive before each run.</p>
  
  <p>The code is:</p>
  
  <pre><code>command="hive -e \"drop database if exists some_db cascade; create database some_db\"";
  eval $command;
  </code></pre>
  
  <p>execution fails with error:</p>
  
  <blockquote>
    <p>FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Unable to clean up java.sql.SQLSyntaxErrorException: Table 'hive.COMPLETED_COMPACTIONS' doesn't exist</p>
  </blockquote>
  
  <p>it passes on rerun,</p>
  
  <pre><code>eval $command;
  </code></pre>
  
  <p>I can't explain also the fact that when calling the command for multiple times, it keep failing alternately.</p>
  
  <p>Appreciate for advice to what happens in Hive and how to make it work on the first attempt, thanks.</p>
  
  <hr>
  
  <p>Details:
  Hive 2.1 running on AWS EMR 5.7, didn't see such behavior on HIVE 1.0</p>
  
  <p>Full Error Stack</p>
  
  <blockquote>
    <p>FAILED: Execution Error, return code 1 from org.apache.hadoop.hive.ql.exec.DDLTask. MetaException(message:Unable to clean up java.sql.SQLSyntaxErrorException: Table 'hive.COMPLETED_COMPACTIONS' doesn't exist
            at org.mariadb.jdbc.internal.util.ExceptionMapper.get(ExceptionMapper.java:125)
            at org.mariadb.jdbc.internal.util.ExceptionMapper.throwException(ExceptionMapper.java:69)
            at org.mariadb.jdbc.MariaDbStatement.executeQueryEpilog(MariaDbStatement.java:259)
            at org.mariadb.jdbc.MariaDbStatement.execute(MariaDbStatement.java:287)
            at org.mariadb.jdbc.MariaDbStatement.executeUpdate(MariaDbStatement.java:470)
            at org.mariadb.jdbc.MariaDbStatement.executeUpdate(MariaDbStatement.java:486)
            at com.jolbox.bonecp.StatementHandle.executeUpdate(StatementHandle.java:497)
            at org.apache.hadoop.hive.metastore.txn.TxnHandler.cleanupRecords(TxnHandler.java:1721)
            at org.apache.hadoop.hive.metastore.AcidEventListener.onDropDatabase(AcidEventListener.java:51)
            at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.drop_database_core(HiveMetaStore.java:1098)
            at org.apache.hadoop.hive.metastore.HiveMetaStore$HMSHandler.drop_database(HiveMetaStore.java:1130)
            at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
            at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
            at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
            at java.lang.reflect.Method.invoke(Method.java:498)
            at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invokeInternal(RetryingHMSHandler.java:140)
            at org.apache.hadoop.hive.metastore.RetryingHMSHandler.invoke(RetryingHMSHandler.java:99)
            at com.sun.proxy.$Proxy19.drop_database(Unknown Source)
            at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Processor$drop_database.getResult(ThriftHiveMetastore.java:10518)
            at org.apache.hadoop.hive.metastore.api.ThriftHiveMetastore$Processor$drop_database.getResult(ThriftHiveMetastore.java:10502)
            at org.apache.thrift.ProcessFunction.process(ProcessFunction.java:39)
            at org.apache.hadoop.hive.metastore.TUGIBasedProcessor$1.run(TUGIBasedProcessor.java:110)
            at org.apache.hadoop.hive.metastore.TUGIBasedProcessor$1.run(TUGIBasedProcessor.java:106)
            at java.security.AccessController.doPrivileged(Native Method)
            at javax.security.auth.Subject.doAs(Subject.java:422)
            at org.apache.hadoop.security.UserGroupInformation.doAs(UserGroupInformation.java:1698)
            at org.apache.hadoop.hive.metastore.TUGIBasedProcessor.process(TUGIBasedProcessor.java:118)
            at org.apache.thrift.server.TThreadPoolServer$WorkerProcess.run(TThreadPoolServer.java:286)
            at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
            at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
            at java.lang.Thread.run(Thread.java:748)
    Caused by: org.mariadb.jdbc.internal.util.dao.QueryException: Table 'hive.COMPLETED_COMPACTIONS' doesn't exist
            at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.getResult(AbstractQueryProtocol.java:479)
            at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.result(AbstractQueryProtocol.java:400)
            at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:381)
            at org.mariadb.jdbc.internal.protocol.AbstractQueryProtocol.executeQuery(AbstractQueryProtocol.java:337)
            at org.mariadb.jdbc.MariaDbStatement.execute(MariaDbStatement.java:277)
            ... 27 more
    Blockquote</p>
  </blockquote>