Repository: phoenix Updated Branches: refs/heads/master 62d787580 -> b8f40bf01
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/b8f40bf0 Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/b8f40bf0 Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/b8f40bf0 Branch: refs/heads/master Commit: b8f40bf01e8b0e9990424777e023c74a762602f3 Parents: 62d7875 Author: Samarth <[email protected]> Authored: Wed Jun 1 11:59:36 2016 -0700 Committer: Samarth <[email protected]> Committed: Wed Jun 1 11:59:36 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/b8f40bf0/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 da75476..558bc38 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 @@ -34,6 +34,7 @@ import java.util.Collections; import java.util.List; import org.apache.phoenix.util.QueryUtil; +import org.junit.Assert; import org.junit.Test; @@ -551,6 +552,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/b8f40bf0/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.
