tkhurana commented on a change in pull request #1183:
URL: https://github.com/apache/phoenix/pull/1183#discussion_r602034647
##########
File path:
phoenix-core/src/it/java/org/apache/phoenix/end2end/OnDuplicateKeyIT.java
##########
@@ -614,6 +614,48 @@ public void
testRowsCreatedViaUpsertOnDuplicateKeyShouldNotBeReturnedInQueryIfNo
conn.close();
}
+ @Test
+ public void testOnDupAndUpsertInSameCommitBatch() throws Exception {
+ Properties props = PropertiesUtil.deepCopy(TEST_PROPERTIES);
+ String tableName = generateUniqueName();
+ try (Connection conn = DriverManager.getConnection(getUrl(), props)) {
+ String ddl = "create table " + tableName + "(pk varchar primary
key, counter1 bigint, counter2 smallint)";
+ conn.createStatement().execute(ddl);
+ createIndex(conn, tableName);
+
+ // row doesn't exist
+ conn.createStatement().execute(String.format("UPSERT INTO %s
VALUES('a',0,1)", tableName));
+ conn.createStatement().execute(String.format(
+ "UPSERT INTO %s VALUES('a',1,1) ON DUPLICATE KEY UPDATE
counter1 = counter1 + 2", tableName));
+ conn.commit();
+ assertRow(conn, tableName, "a", 2, 1);
+
+ // row exists
+ conn.createStatement().execute(String.format("UPSERT INTO %s
VALUES('a', 7, 4)", tableName));
+ conn.createStatement().execute(String.format(
+ "UPSERT INTO %s VALUES('a',1,1) ON DUPLICATE KEY UPDATE
counter1 = counter1 + 2", tableName));
+ conn.commit();
+ assertRow(conn, tableName, "a", 9, 4);
+
+ // partial update
+ conn.createStatement().execute(String.format(
+ "UPSERT INTO %s (pk, counter2) VALUES('a',100) ON DUPLICATE
KEY UPDATE counter1 = counter1 + 2", tableName));
+ conn.createStatement().execute(String.format(
+ "UPSERT INTO %s (pk, counter2) VALUES ('a',125)", tableName));
+ conn.commit();
+ assertRow(conn, tableName, "a", 11, 125);
Review comment:
There is no index defined yet. This change addresses the problem on the
data table.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
For queries about this service, please contact Infrastructure at:
[email protected]