commit 45cca9693a444f3ea06d07056d74c55fefb6f071 Author: Daniel Dai Date: Sun Oct 28 23:33:19 2018 -0700 HIVE-20815: JdbcRecordReader.next shall not eat exception 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 boolean next(LongWritable key, MapWritable value) throws IOException { } } catch (Exception e) { - LOGGER.error("An error occurred while reading the next record from DB.", e); - return false; + throw new IOException(e); } } 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 607c45c..fa3f3b0 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 int getTotalNumberOfRecords(Configuration conf) throws HiveJdbcDatabaseAc 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); } } 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; 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.