Repository: phoenix Updated Branches: refs/heads/4.x-HBase-0.98 5cb996511 -> e8c4582fa
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/e8c4582f Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/e8c4582f Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/e8c4582f Branch: refs/heads/4.x-HBase-0.98 Commit: e8c4582fa6ecd6d061684fa6b98e4c93672ec7ab Parents: 5cb9965 Author: Samarth <[email protected]> Authored: Wed Jun 1 11:06:39 2016 -0700 Committer: Samarth <[email protected]> Committed: Wed Jun 1 11:06:39 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/e8c4582f/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/e8c4582f/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.
