You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@hive.apache.org by da...@apache.org on 2018/11/03 22:25:15 UTC

hive git commit: HIVE-20815: JdbcRecordReader.next shall not eat exception (Daniel Dai, reviewed by Thejas Nair)

Repository: hive
Updated Branches:
  refs/heads/master ae1eb15d4 -> bb777512f


HIVE-20815: JdbcRecordReader.next shall not eat exception (Daniel Dai, reviewed by Thejas Nair)

Signed-off-by: Thejas M Nair <th...@hortonworks.com>


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

Branch: refs/heads/master
Commit: bb777512f9dd3efc0590b960778fd7ca2e3bab21
Parents: ae1eb15
Author: Daniel Dai <da...@gmail.com>
Authored: Sat Nov 3 15:24:36 2018 -0700
Committer: Daniel Dai <da...@gmail.com>
Committed: Sat Nov 3 15:24:43 2018 -0700

----------------------------------------------------------------------
 .../hive/storage/jdbc/JdbcRecordReader.java     |  3 +-
 .../jdbc/dao/GenericJdbcDatabaseAccessor.java   |  2 +-
 .../clientnegative/external_jdbc_negative.q     | 29 ++++++++
 .../clientnegative/external_jdbc_negative.q.out | 72 ++++++++++++++++++++
 4 files changed, 103 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/bb777512/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/JdbcRecordReader.java
----------------------------------------------------------------------
diff --git a/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/JdbcRecordReader.java b/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/JdbcRecordReader.java
index a3248b4..ce2871c 100644
--- a/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/JdbcRecordReader.java
+++ b/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/JdbcRecordReader.java
@@ -82,8 +82,7 @@ public class JdbcRecordReader implements RecordReader<LongWritable, MapWritable>
       }
     }
     catch (Exception e) {
-      LOGGER.error("An error occurred while reading the next record from DB.", e);
-      return false;
+      throw new IOException(e);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/bb777512/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/dao/GenericJdbcDatabaseAccessor.java
----------------------------------------------------------------------
diff --git a/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/dao/GenericJdbcDatabaseAccessor.java b/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/dao/GenericJdbcDatabaseAccessor.java
index 95d54b4..a971183 100644
--- a/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/dao/GenericJdbcDatabaseAccessor.java
+++ b/jdbc-handler/src/main/java/org/apache/hive/storage/jdbc/dao/GenericJdbcDatabaseAccessor.java
@@ -174,7 +174,7 @@ public class GenericJdbcDatabaseAccessor implements DatabaseAccessor {
     catch (Exception e) {
       LOGGER.error("Caught exception while trying to execute query", e);
       cleanupResources(conn, ps, rs);
-      throw new HiveJdbcDatabaseAccessException("Caught exception while trying to execute query", e);
+      throw new HiveJdbcDatabaseAccessException("Caught exception while trying to execute query:" + e.getMessage(), e);
     }
   }
 

http://git-wip-us.apache.org/repos/asf/hive/blob/bb777512/ql/src/test/queries/clientnegative/external_jdbc_negative.q
----------------------------------------------------------------------
diff --git a/ql/src/test/queries/clientnegative/external_jdbc_negative.q b/ql/src/test/queries/clientnegative/external_jdbc_negative.q
new file mode 100644
index 0000000..5937391
--- /dev/null
+++ b/ql/src/test/queries/clientnegative/external_jdbc_negative.q
@@ -0,0 +1,29 @@
+--! qt:dataset:src
+
+CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput';
+
+FROM src
+SELECT
+dboutput ('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_negative;create=true','user1','passwd1',
+'CREATE TABLE EXTERNAL_JDBC_NEGATIVE_TABLE1 ("ikey" INTEGER)' ),
+dboutput('jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_negative','user1','passwd1',
+'INSERT INTO EXTERNAL_JDBC_NEGATIVE_TABLE1 ("ikey") VALUES (?,?,?,?)','20')
+limit 1;
+
+CREATE EXTERNAL TABLE db1_ext_negative1
+(
+ ikey int,
+ bkey bigint
+)
+STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
+TBLPROPERTIES (
+                "hive.sql.database.type" = "DERBY",
+                "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
+                "hive.sql.jdbc.url" = "jdbc:derby:;databaseName=${system:test.tmp.dir}/test_derby_negative;collation=TERRITORY_BASED:PRIMARY",
+                "hive.sql.dbcp.username" = "user1",
+                "hive.sql.dbcp.password" = "passwd1",
+                "hive.sql.table" = "EXTERNAL_JDBC_NEGATIVE_TABLE1",
+                "hive.sql.dbcp.maxActive" = "1"
+);
+
+SELECT * FROM db1_ext_negative1;

http://git-wip-us.apache.org/repos/asf/hive/blob/bb777512/ql/src/test/results/clientnegative/external_jdbc_negative.q.out
----------------------------------------------------------------------
diff --git a/ql/src/test/results/clientnegative/external_jdbc_negative.q.out b/ql/src/test/results/clientnegative/external_jdbc_negative.q.out
new file mode 100644
index 0000000..0fe51aa
--- /dev/null
+++ b/ql/src/test/results/clientnegative/external_jdbc_negative.q.out
@@ -0,0 +1,72 @@
+PREHOOK: query: CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput'
+PREHOOK: type: CREATEFUNCTION
+PREHOOK: Output: dboutput
+POSTHOOK: query: CREATE TEMPORARY FUNCTION dboutput AS 'org.apache.hadoop.hive.contrib.genericudf.example.GenericUDFDBOutput'
+POSTHOOK: type: CREATEFUNCTION
+POSTHOOK: Output: dboutput
+PREHOOK: query: FROM src
+SELECT
+#### A masked pattern was here ####
+'CREATE TABLE EXTERNAL_JDBC_NEGATIVE_TABLE1 ("ikey" INTEGER)' ),
+#### A masked pattern was here ####
+'INSERT INTO EXTERNAL_JDBC_NEGATIVE_TABLE1 ("ikey") VALUES (?,?,?,?)','20')
+limit 1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@src
+#### A masked pattern was here ####
+POSTHOOK: query: FROM src
+SELECT
+#### A masked pattern was here ####
+'CREATE TABLE EXTERNAL_JDBC_NEGATIVE_TABLE1 ("ikey" INTEGER)' ),
+#### A masked pattern was here ####
+'INSERT INTO EXTERNAL_JDBC_NEGATIVE_TABLE1 ("ikey") VALUES (?,?,?,?)','20')
+limit 1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@src
+#### A masked pattern was here ####
+0	1
+PREHOOK: query: CREATE EXTERNAL TABLE db1_ext_negative1
+(
+ ikey int,
+ bkey bigint
+)
+STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
+TBLPROPERTIES (
+                "hive.sql.database.type" = "DERBY",
+                "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
+#### A masked pattern was here ####
+                "hive.sql.dbcp.username" = "user1",
+                "hive.sql.dbcp.password" = "passwd1",
+                "hive.sql.table" = "EXTERNAL_JDBC_NEGATIVE_TABLE1",
+                "hive.sql.dbcp.maxActive" = "1"
+)
+PREHOOK: type: CREATETABLE
+PREHOOK: Output: database:default
+PREHOOK: Output: default@db1_ext_negative1
+POSTHOOK: query: CREATE EXTERNAL TABLE db1_ext_negative1
+(
+ ikey int,
+ bkey bigint
+)
+STORED BY 'org.apache.hive.storage.jdbc.JdbcStorageHandler'
+TBLPROPERTIES (
+                "hive.sql.database.type" = "DERBY",
+                "hive.sql.jdbc.driver" = "org.apache.derby.jdbc.EmbeddedDriver",
+#### A masked pattern was here ####
+                "hive.sql.dbcp.username" = "user1",
+                "hive.sql.dbcp.password" = "passwd1",
+                "hive.sql.table" = "EXTERNAL_JDBC_NEGATIVE_TABLE1",
+                "hive.sql.dbcp.maxActive" = "1"
+)
+POSTHOOK: type: CREATETABLE
+POSTHOOK: Output: database:default
+POSTHOOK: Output: default@db1_ext_negative1
+PREHOOK: query: SELECT * FROM db1_ext_negative1
+PREHOOK: type: QUERY
+PREHOOK: Input: default@db1_ext_negative1
+#### A masked pattern was here ####
+POSTHOOK: query: SELECT * FROM db1_ext_negative1
+POSTHOOK: type: QUERY
+POSTHOOK: Input: default@db1_ext_negative1
+#### A masked pattern was here ####
+Failed with exception java.io.IOException:java.io.IOException: org.apache.hive.storage.jdbc.exception.HiveJdbcDatabaseAccessException: Caught exception while trying to execute query:Column 'bkey' is either not in any table in the FROM list or appears within a join specification and is outside the scope of the join specification or appears in a HAVING clause and is not in the GROUP BY list. If this is a CREATE or ALTER TABLE  statement then 'bkey' is not a column in the target table.