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

hive git commit: HIVE-20218: make sure Statement.executeUpdate() returns number of rows affected (Eugene Koifman, reviewed by Ashutosh Chauhan)

Repository: hive
Updated Branches:
  refs/heads/master cce3a0521 -> 92ecdd97b


HIVE-20218: make sure Statement.executeUpdate() returns number of rows affected (Eugene Koifman, reviewed by Ashutosh Chauhan)


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

Branch: refs/heads/master
Commit: 92ecdd97bc183b939d1e074f23f52f96e6fafe25
Parents: cce3a05
Author: Eugene Koifman <ek...@apache.org>
Authored: Sun Jul 22 16:25:57 2018 -0700
Committer: Eugene Koifman <ek...@apache.org>
Committed: Sun Jul 22 16:25:57 2018 -0700

----------------------------------------------------------------------
 .../org/apache/hive/jdbc/TestJdbcDriver2.java   | 31 ++++++++++++++++++++
 .../apache/hive/jdbc/HivePreparedStatement.java |  3 +-
 .../org/apache/hive/jdbc/HiveStatement.java     |  3 +-
 3 files changed, 34 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/hive/blob/92ecdd97/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
----------------------------------------------------------------------
diff --git a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
index 850b2d5..8f552b0 100644
--- a/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
+++ b/itests/hive-unit/src/test/java/org/apache/hive/jdbc/TestJdbcDriver2.java
@@ -209,6 +209,37 @@ public class TestJdbcDriver2 {
     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();

http://git-wip-us.apache.org/repos/asf/hive/blob/92ecdd97/jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java
----------------------------------------------------------------------
diff --git a/jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java b/jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java
index 77a1797..f86b112 100644
--- a/jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java
+++ b/jdbc/src/java/org/apache/hive/jdbc/HivePreparedStatement.java
@@ -119,8 +119,7 @@ public class HivePreparedStatement extends HiveStatement implements PreparedStat
    */
 
   public int executeUpdate() throws SQLException {
-    super.executeUpdate(updateSql(sql, parameters));
-    return 0;
+    return super.executeUpdate(updateSql(sql, parameters));
   }
 
   /**

http://git-wip-us.apache.org/repos/asf/hive/blob/92ecdd97/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
----------------------------------------------------------------------
diff --git a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
index 0b38f9c..89ff514 100644
--- a/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
+++ b/jdbc/src/java/org/apache/hive/jdbc/HiveStatement.java
@@ -511,7 +511,8 @@ public class HiveStatement implements java.sql.Statement {
   @Override
   public int executeUpdate(String sql) throws SQLException {
     execute(sql);
-    return 0;
+    return getUpdateCount();
+    //return getLargeUpdateCount(); - not currently implemented... wrong type
   }
 
   /*