Repository: phoenix
Updated Branches:
  refs/heads/4.x-HBase-1.0 90ac492a9 -> 837838980


PHOENIX-2919 PreparedStatement Returns Incorrect Number of Deleted Records


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

Branch: refs/heads/4.x-HBase-1.0
Commit: 837838980ef36bc1bda8406b97c89f4cde890f44
Parents: 90ac492
Author: Samarth <[email protected]>
Authored: Wed Jun 1 12:04:02 2016 -0700
Committer: Samarth <[email protected]>
Committed: Wed Jun 1 12:04:02 2016 -0700

----------------------------------------------------------------------
 .../org/apache/phoenix/end2end/DeleteIT.java    | 39 ++++++++++++++++++++
 .../apache/phoenix/compile/DeleteCompiler.java  |  2 +-
 2 files changed, 40 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/83783898/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java 
b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
index 10152e3..abcbb95 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/DeleteIT.java
@@ -35,6 +35,7 @@ import java.util.List;
 
 import org.apache.phoenix.util.MetaDataUtil;
 import org.apache.phoenix.util.QueryUtil;
+import org.junit.Assert;
 import org.junit.Test;
 
 
@@ -548,6 +549,44 @@ public class DeleteIT extends BaseHBaseManagedTimeIT {
             assertEquals(0, rs.getLong(1));
         }
     }
+    
+    @Test
+    public void testServerSideDeleteAutoCommitOn() throws Exception {
+        testDeleteCount(true, null);
+    }
+    
+    @Test
+    public void testClientSideDeleteCountAutoCommitOff() throws Exception {
+        testDeleteCount(false, null);
+    }
+    
+    @Test
+    public void testClientSideDeleteAutoCommitOn() throws Exception {
+        testDeleteCount(true, 1000);
+    }
+    
+    private void testDeleteCount(boolean autoCommit, Integer limit) throws 
Exception {
+        String ddl = "CREATE TABLE IF NOT EXISTS TEST_TABLE (pk1 DECIMAL NOT 
NULL, v1 VARCHAR CONSTRAINT PK PRIMARY KEY (pk1))";
+        int numRecords = 1010;
+        try (Connection conn = DriverManager.getConnection(getUrl())) {
+            conn.createStatement().execute(ddl);
+            Statement stmt = conn.createStatement();
+            for (int i = 0; i < numRecords ; i++) {
+                stmt.executeUpdate("UPSERT INTO TEST_TABLE (pk1, v1) VALUES (" 
+ i + ",'value')");
+            }
+            conn.commit();
+            conn.setAutoCommit(autoCommit);
+            String delete = "DELETE FROM TEST_TABLE WHERE (pk1) <= (" + 
numRecords + ")" + (limit == null ? "" : (" limit " + limit));
+            try (PreparedStatement pstmt = conn.prepareStatement(delete)) {
+                int numberOfDeletes = pstmt.executeUpdate();
+                assertEquals(limit == null ? numRecords : limit, 
numberOfDeletes);
+                if (!autoCommit) {
+                    conn.commit();
+                }
+            }
+        }
+
+    }
 }
 
 

http://git-wip-us.apache.org/repos/asf/phoenix/blob/83783898/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
----------------------------------------------------------------------
diff --git 
a/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java 
b/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
index fa3dd62..696b74f 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/DeleteCompiler.java
@@ -182,7 +182,7 @@ public class DeleteCompiler {
             }
 
             // If auto commit is true, this last batch will be committed upon 
return
-            int nCommittedRows = rowCount / batchSize * batchSize;
+            int nCommittedRows = isAutoCommit ? (rowCount / batchSize * 
batchSize) : 0;
             MutationState state = new MutationState(targetTableRef, mutations, 
nCommittedRows, maxSize, connection);
             if (indexTableRef != null) {
                 // To prevent the counting of these index rows, we have a 
negative for remainingRows.

Reply via email to