diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java index 4a9af80fdc..33388e0f01 100644 --- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java +++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcWithMiniHS2.java @@ -558,6 +558,46 @@ public void testMetadataQueriesWithSerializeThriftInTasks() throws Exception { } @Test + public void testMultipleResultSets() throws Exception { + Statement stmt = conTestDb.createStatement(); + setSerializeInTasksInConf(stmt); + stmt.execute("drop table if exists testMultipleResultSets1"); + stmt.execute("drop table if exists testMultipleResultSets2"); + stmt.execute("create table testMultipleResultSets1 (orderid int, orderdate string, customerid int)"); + stmt.execute("create table testMultipleResultSets2 (customerid int, customername string, customercountry string)"); + stmt.execute("insert into testMultipleResultSets1 values (123, 'David', 'America'), " + + "(246, 'John', 'Canada'), (356, 'Mary', 'CostaRica')"); + stmt.execute("insert into testMultipleResultSets2 values (1, '2015-09-09', 123), (2, '2015-10-10', 246), " + + "(3, '2015-11-11', 356)"); + ResultSet rs1 = + stmt.executeQuery("select * from testMultipleResultSets1"); + ResultSet rs2 = + stmt.executeQuery("select * from testMultipleResultSets2"); + + Map expectedResult = new HashMap(); + expectedResult.put(1, "David"); + expectedResult.put(2, "John"); + expectedResult.put(3, "Mary"); + for (int i = 1; i < 4; i++) { + assertTrue(rs1.next()); + assertEquals(rs1.getString(2), expectedResult.get(i)); + } + + expectedResult = new HashMap(); + expectedResult.put(1, "2015-09-09"); + expectedResult.put(2, "2015-10-10"); + expectedResult.put(3, "2015-11-11"); + for (int i = 1; i < 4; i++) { + assertTrue(rs2.next()); + assertEquals(rs2.getString(2), expectedResult.get(i)); + } + + stmt.execute("drop table testMultipleResultSets1"); + stmt.execute("drop table testMultipleResultSets2"); + stmt.close(); + } + + @Test public void testSelectThriftSerializeInTasks() throws Exception { Statement stmt = conTestDb.createStatement(); setSerializeInTasksInConf(stmt); diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java index b743b46a6c..0fe33cd878 100644 --- a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java +++ b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java @@ -426,7 +426,6 @@ private void checkConnection(String action) throws SQLException { * @throws SQLException */ private void reInitState() throws SQLException { - closeStatementIfNeeded(); isCancelled = false; isQueryClosed = false; isLogBeingGenerated = true;