You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by vi...@apache.org on 2018/04/03 17:37:02 UTC

hive git commit: HIVE-18877 : HiveSchemaTool.validateSchemaTables() should wrap a SQLException when rethrowing (Andrew Sherman reviewed by Vihang Karajgaonkar)

Repository: hive
Updated Branches:
  refs/heads/master ec173399b -> 00d0e56e3


HIVE-18877 : HiveSchemaTool.validateSchemaTables() should wrap a SQLException when rethrowing (Andrew Sherman reviewed by Vihang Karajgaonkar)


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

Branch: refs/heads/master
Commit: 00d0e56e3fe10242101a3fd139f5706df9c47442
Parents: ec17339
Author: Andrew Sherman <as...@cloudera.com>
Authored: Tue Apr 3 10:23:30 2018 -0700
Committer: Vihang Karajgaonkar <vi...@cloudera.com>
Committed: Tue Apr 3 10:36:46 2018 -0700

----------------------------------------------------------------------
 .../org/apache/hive/beeline/HiveSchemaTool.java |  2 +-
 itests/hive-unit/pom.xml                        |  5 +++
 .../org/apache/hive/beeline/TestSchemaTool.java | 38 +++++++++++++++++++-
 3 files changed, 43 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/00d0e56e/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
----------------------------------------------------------------------
diff --git a/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java b/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
index 0728289..040724a 100644
--- a/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
+++ b/beeline/src/java/org/apache/hive/beeline/HiveSchemaTool.java
@@ -750,7 +750,7 @@ public class HiveSchemaTool {
         LOG.debug("Found table " + table + " in HMS dbstore");
       }
     } catch (SQLException e) {
-      throw new HiveMetaException("Failed to retrieve schema tables from Hive Metastore DB," + e.getMessage());
+      throw new HiveMetaException("Failed to retrieve schema tables from Hive Metastore DB", e);
     } finally {
       if (rs != null) {
         try {

http://git-wip-us.apache.org/repos/asf/hive/blob/00d0e56e/itests/hive-unit/pom.xml
----------------------------------------------------------------------
diff --git a/itests/hive-unit/pom.xml b/itests/hive-unit/pom.xml
index 626bbfb..6923ee5 100644
--- a/itests/hive-unit/pom.xml
+++ b/itests/hive-unit/pom.xml
@@ -468,6 +468,11 @@
       <version>${plexus.version}</version>
       <scope>test</scope>
     </dependency>
+    <dependency>
+      <groupId>commons-dbcp</groupId>
+      <artifactId>commons-dbcp</artifactId>
+      <version>${commons-dbcp.version}</version>
+    </dependency>
   </dependencies>
 
   <profiles>

http://git-wip-us.apache.org/repos/asf/hive/blob/00d0e56e/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java
index d92a50c..ac93abc 100644
--- a/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java
+++ b/itests/hive-unit/src/test/java/org/apache/hive/beeline/TestSchemaTool.java
@@ -27,10 +27,13 @@ import java.io.OutputStream;
 import java.io.PrintStream;
 import java.net.URI;
 import java.sql.Connection;
+import java.sql.DatabaseMetaData;
+import java.sql.SQLException;
 import java.util.Random;
 
 import junit.framework.TestCase;
 
+import org.apache.commons.dbcp.DelegatingConnection;
 import org.apache.commons.io.FileUtils;
 import org.apache.commons.lang.StringUtils;
 import org.apache.hadoop.hive.conf.HiveConf;
@@ -153,7 +156,24 @@ public class TestSchemaTool extends TestCase {
     schemaTool.runBeeLine(scriptFile.getPath());
     isValid = schemaTool.validateSchemaTables(conn);
     assertTrue(isValid);
-   }
+
+    // Check that an exception from getMetaData() is reported correctly
+    try {
+      // Make a Connection object that will throw an exception
+      BadMetaDataConnection bad = new BadMetaDataConnection(conn);
+      schemaTool.validateSchemaTables(bad);
+      fail("did not get expected exception");
+    } catch (HiveMetaException hme) {
+      String message = hme.getMessage();
+      assertTrue("Bad HiveMetaException message :" + message,
+          message.contains("Failed to retrieve schema tables from Hive Metastore DB"));
+      Throwable cause = hme.getCause();
+      assertNotNull("HiveMetaException did not contain a cause", cause);
+      String causeMessage = cause.getMessage();
+      assertTrue("Bad SQLException message: " + causeMessage, causeMessage.contains(
+          BadMetaDataConnection.FAILURE_TEXT));
+    }
+  }
 
   /*
    * Test the validation of incorrect NULL values in the tables
@@ -759,4 +779,20 @@ public class TestSchemaTool extends TestCase {
      File scriptFile = generateTestScript(scripts);
      schemaTool.runBeeLine(scriptFile.getPath());
   }
+
+  /**
+   * A mock Connection class that throws an exception out of getMetaData().
+   */
+  class BadMetaDataConnection extends DelegatingConnection {
+    static final String FAILURE_TEXT = "fault injected";
+
+    BadMetaDataConnection(Connection connection) {
+      super(connection);
+    }
+
+    @Override
+    public DatabaseMetaData getMetaData() throws SQLException {
+      throw new SQLException(FAILURE_TEXT);
+    }
+  }
 }