You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@phoenix.apache.org by ka...@apache.org on 2018/08/29 07:13:15 UTC
phoenix git commit: PHOENIX-3178 Row count incorrect for UPSERT
SELECT when auto commit is false
Repository: phoenix
Updated Branches:
refs/heads/master 7b645142b -> fa20ff297
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/fa20ff29
Tree: http://git-wip-us.apache.org/repos/asf/phoenix/tree/fa20ff29
Diff: http://git-wip-us.apache.org/repos/asf/phoenix/diff/fa20ff29
Branch: refs/heads/master
Commit: fa20ff297ed2de19b6e736b39c73521045160115
Parents: 7b64514
Author: s.kadam <s....@gus.com>
Authored: Tue Aug 28 15:50:39 2018 -0700
Committer: Karan Mehta <ka...@gmail.com>
Committed: Tue Aug 28 23:59:08 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/fa20ff29/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/fa20ff29/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 af4a1dc..2ce6a4d 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);
}
}