diff --git itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java index 850b2d558e..8f552b06ff 100644 --- itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java +++ itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java @@ -209,6 +209,37 @@ public static void setUpBeforeClass() throws SQLException, ClassNotFoundExceptio stmt.close(); } + + @Test + public void testExceucteUpdateCounts() throws Exception { + Statement stmt = con.createStatement(); + stmt.execute("set " + ConfVars.HIVE_SUPPORT_CONCURRENCY.varname + "=true"); + stmt.execute("set " + ConfVars.HIVE_TXN_MANAGER.varname + + "=org.apache.hadoop.hive.ql.lockmgr.DbTxnManager"); + stmt.execute("create table transactional_crud (a int, b int) stored as orc " + + "tblproperties('transactional'='true', 'transactional_properties'='default')"); + int count = stmt.executeUpdate("insert into transactional_crud values(1,2),(3,4),(5,6)"); + assertEquals("Statement insert", 3, count); + count = stmt.executeUpdate("update transactional_crud set b = 17 where a <= 3"); + assertEquals("Statement update", 2, count); + count = stmt.executeUpdate("delete from transactional_crud where b = 6"); + assertEquals("Statement delete", 1, count); + + stmt.close(); + PreparedStatement pStmt = + con.prepareStatement("update transactional_crud set b = ? where a = ? or a = ?"); + pStmt.setInt(1, 15); + pStmt.setInt(2, 1); + pStmt.setInt(3, 3); + count = pStmt.executeUpdate(); + assertEquals("2 row PreparedStatement update", 2, count); + pStmt.setInt(1, 19); + pStmt.setInt(2, 3); + pStmt.setInt(3, 3); + count = pStmt.executeUpdate(); + assertEquals("1 row PreparedStatement update", 1, count); + } + @AfterClass public static void tearDownAfterClass() throws Exception { Statement stmt = con.createStatement(); diff --git jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java index 77a1797715..f86b11248e 100644 --- jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java +++ jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java @@ -119,8 +119,7 @@ public ResultSet executeQuery() throws SQLException { */ public int executeUpdate() throws SQLException { - super.executeUpdate(updateSql(sql, parameters)); - return 0; + return super.executeUpdate(updateSql(sql, parameters)); } /** diff --git jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java index 0b38f9c93a..89ff514c45 100644 --- jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java +++ jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java @@ -511,7 +511,8 @@ public ResultSet executeQuery(String sql) throws SQLException { @Override public int executeUpdate(String sql) throws SQLException { execute(sql); - return 0; + return getUpdateCount(); + //return getLargeUpdateCount(); - not currently implemented... wrong type } /*