You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ja...@apache.org on 2018/09/24 15:28:41 UTC

[36/50] [abbrv] phoenix git commit: PHOENIX-3178 Row count incorrect for UPSERT SELECT when auto commit is false

PHOENIX-3178 Row count incorrect for UPSERT SELECT when auto commit is false


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

Branch: refs/heads/omid2
Commit: a3e08104aa6d7e907c12950b2a6eb7bc9d9fb7e5
Parents: b0cc455
Author: s.kadam <s....@gus.com>
Authored: Tue Aug 28 15:44:56 2018 -0700
Committer: Karan Mehta <ka...@gmail.com>
Committed: Wed Aug 29 00:21:45 2018 -0700

----------------------------------------------------------------------
 .../end2end/UpsertSelectAutoCommitIT.java       | 31 ++++++++++++++++++--
 .../apache/phoenix/compile/UpsertCompiler.java  | 10 +++++--
 2 files changed, 37 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/phoenix/blob/a3e08104/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
index 38d48d6..3966f15 100644
--- a/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
+++ b/phoenix-core/src/it/java/org/apache/phoenix/end2end/UpsertSelectAutoCommitIT.java
@@ -151,8 +151,7 @@ public class UpsertSelectAutoCommitIT extends ParallelStatsDisabledIT {
         stmt.executeUpdate();
         conn.commit();
     }
-    
-    
+
     @Test
     public void testUpsertSelectDoesntSeeUpsertedData() throws Exception {
         Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
@@ -201,4 +200,32 @@ public class UpsertSelectAutoCommitIT extends ParallelStatsDisabledIT {
         connection.close();
     }
 
+    @Test
+    public void testRowCountWithNoAutoCommitOnUpsertSelect() throws Exception {
+        Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+        props.setProperty(QueryServices.MUTATE_BATCH_SIZE_ATTRIB, Integer.toString(3));
+        props.setProperty(QueryServices.SCAN_CACHE_SIZE_ATTRIB, Integer.toString(3));
+        props.setProperty(QueryServices.SCAN_RESULT_CHUNK_SIZE, Integer.toString(3));
+        Connection conn = DriverManager.getConnection(getUrl(), props);
+        conn.setAutoCommit(false);
+        String tableName = generateUniqueName();
+
+        conn.createStatement().execute("CREATE SEQUENCE "+ tableName);
+        conn.createStatement().execute(
+                "CREATE TABLE " + tableName + " (pk INTEGER PRIMARY KEY, val INTEGER)");
+
+        conn.createStatement().execute(
+                "UPSERT INTO " + tableName + " VALUES (NEXT VALUE FOR keys,1)");
+        conn.commit();
+        for (int i=0; i<6; i++) {
+            Statement stmt = conn.createStatement();
+            int upsertCount = stmt.executeUpdate(
+                    "UPSERT INTO " + tableName + " SELECT NEXT VALUE FOR keys, val FROM "
+                            + tableName);
+            conn.commit();
+            assertEquals((int)Math.pow(2, i), upsertCount);
+        }
+        conn.close();
+    }
+
 }

http://git-wip-us.apache.org/repos/asf/phoenix/blob/a3e08104/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
----------------------------------------------------------------------
diff --git a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
index 9d75bba..d0dd2cf 100644
--- a/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
+++ b/phoenix-core/src/main/java/org/apache/phoenix/compile/UpsertCompiler.java
@@ -185,6 +185,7 @@ public class UpsertCompiler {
                     QueryServicesOptions.DEFAULT_MAX_MUTATION_SIZE_BYTES);
         int batchSize = Math.min(connection.getMutateBatchSize(), maxSize);
         boolean isAutoCommit = connection.getAutoCommit();
+        int sizeOffset = 0;
         int numSplColumns =
                 (tableRef.getTable().isMultiTenant() ? 1 : 0)
                         + (tableRef.getTable().getViewIndexId() != null ? 1 : 0);
@@ -249,8 +250,13 @@ public class UpsertCompiler {
                     mutation.clear();
                 }
             }
-            // If auto commit is true, this last batch will be committed upon return
-            return new MutationState(tableRef, mutation, rowCount / batchSize * batchSize, maxSize, maxSizeBytes, connection);
+
+            if (isAutoCommit) {
+                // If auto commit is true, this last batch will be committed upon return
+                sizeOffset = rowCount / batchSize * batchSize;
+            }
+            return new MutationState(tableRef, mutation, sizeOffset, maxSize,
+                    maxSizeBytes, connection);
         }
     }