Github user ryzuo commented on a diff in the pull request:
https://github.com/apache/incubator-trafodion/pull/211#discussion_r46903367
--- Diff:
tests/phx/src/test/java/org/trafodion/phoenix/end2end/BatchTest.java ---
@@ -118,69 +120,126 @@ public void testBatchInsertNegative() throws
Exception {
// Initialize the expected status array for executeBatch() success
for all rows,
// except for row 2 and row 6, to which we will pass duplicate ID
values on
// purpose in actual insert later to make an unique value conflict
error. The
- // returned status value should be
+ // returned status value should be
+ String nameSuffix = "Traf The World ";
expectedStatusArray = new int[10];
+
int[] expectedIdArray = new int[8];
String[] expectedNameArray = new String[8];
- for(int i=0, j=0; i < 10; ++i, ++j) {
+ int[] idArray = new int[10];
+ String[] nameArray = new String[10];
+
+ for(int i=0, j=0; i < 10; ++i) {
expectedStatusArray[i] = -2;
+ idArray[i] = i;
+ nameArray[i] = nameSuffix + i;
+ expectedIdArray[j] = i;
+ expectedNameArray[j] = nameArray[i];
switch(i) {
- case 8:
- case 9:
- break;
case 1:
- case 4:
- expectedIdArray[i] = ++j;
- expectedNameArray[i] = "Traf The World " + j;
+ case 5:
+ idArray[i] = i-1;
+ expectedStatusArray[i] = -3;
break;
default:
- expectedIdArray[i] = j;
- expectedNameArray[i] = "Traf The World " + j;
+ j++;
break;
}
}
int expectedRowCount = 8;
- // Start to prepare and execute the batch insert
- PreparedStatement upsertStmt = conn.prepareStatement(strUpsert);
+ // Start to prepare and execute the batch upsert
+ PreparedStatement insertStmt = conn.prepareStatement(strInsert);
for(int i=0; i < 10; ++i) {
+ insertStmt.setInt(1, idArray[i]);
+ insertStmt.setString(2, nameArray[i]);
+ insertStmt.addBatch();
+ }
+
+ try {
+ statusArray = insertStmt.executeBatch();
+ } catch(SQLException sqle) {
+ assertEquals("Batch update failed. See next exception for
details", sqle.getMessage());
+ SQLException e = null;
+ e = sqle.getNextException();
+ do {
+ assertTrue(e.getMessage().contains("ERROR[8102] The
operation is prevented by a unique constraint"));
+ } while((e = e.getNextException()) != null);
+ }
+
+ //assertArrayEquals(expectedStatusArray, statusArray);
+
+ int rowCount = 0;
+ ResultSet rs = conn.createStatement().executeQuery(strSelect);
+ while(rs.next()) {
+ //System.out.println("ID = " + rs.getString(1) + ", Name = " +
rs.getString(2));
+ //assertEquals(expectedIdArray[rs.getRow()-1], rs.getInt(1));
--- End diff --
Hi Hans, thanks for the reminding here. For now, the result I observed is
because of the duplicate primary key, the whole batch failed, thus there's no
status array generated, neither no row is inserted. My understanding before was
a failure of individual row should not cause the whole batch fails, and as I
recall, SQ worked that way, but now Traf does not.
---
If your project is set up for it, you can reply to this email and have your
reply appear on GitHub as well. If your project does not have this feature
enabled and wishes so, or if the feature is enabled but not working, please
contact infrastructure at [email protected] or file a JIRA ticket
with INFRA.
---